backspace issue on linux file
You need to change file preferences: go to Preferences -> Files and change "Create new file as " to UNIX. Also, your might want to enable "Check invalid CR/LF, null character when loading" option.
Bash - process backspace control character when redirecting output to file
Thanks for your comments! I ended up piping the output of that program to AWK Script I linked in the question. I get a well-formed file in the end.
the_program | ./awk_crush.sh > output.txt
The only downside is that I get the output only once the program itself is finished, even though the initial output exceeds 5M and should be passed in the lesser chunks. I don't know the exact reason, perhaps AWK script waits for EOF on stdin. Either way, on more modern system I would use
stdbuf -oL the_program | ./awk_crush.sh > output.txt
to process the output line-by-line. I'm stuck on RHEL4 with expired support though, so I'm unable to use neither stdbuf
nor unbuffer
. I'll leave it as-is, it's fine too.
The contents of awk_crush.sh are based on this answer, except with ^H
sequences (which are supposed to be ASCII 08
characters entered via VIM commands) replaced with escape sequence \b
:
#!/usr/bin/awk -f
function crushify(data) {
while (data ~ /[^\b]\b/) {
gsub(/[^\b]\b/, "", data)
}
print data
}
crushify($0)
Basically, it replaces character before \b
and \b
itself with empty string, and repeats it while there are \b
in the string - just what I needed. It doesn't care for other escape sequences though, but if it's necessary, there's a more complete SED solution by Thomas Dickey.
Backspace key not working in Vim/vi
To allow backspacing over everything in insert mode (including automatically inserted indentation, line breaks and start of insert) you can set the backspace
option:
:set backspace=indent,eol,start
or
:set backspace=2 "compatible with version 5.4 and earlier
By default this option is empty, not allowing you to backspace over the above-mentioned things. This is the standard Vi behavior.
You can put this line to your vimrc
file to have it set automatically when Vim starts:
set backspace=indent,eol,start " more powerful backspacing
Also, starting from Vim 8.0 if no user vimrc file is found, Vim will set backspace
to this value by loading the defaults.vim
script.
Bash backspace character correct use
The correct version of the file is the one saved on the filesystem. Sublime text and gedit are reading the file and representing in different ways.
backspace does not work git bash
I had this same problem today after switching to mintty with a fresh version of git. In my case, it was an old .bashrc file I'd been carrying around for many years with the line export TERM=ansi
. After removing that and starting a new bash, everything works again.
More generally, to debug, I was suspicious of all the dot-config stuff in my home directory--so I moved things like .bash_profile, .bashrc, .inputrc, etc. into a temporary directory where they wouldn't be read by bash. Then, I started bash and saw that it worked. I mention it because, if it isn't specifically the TERM issue I had, you might be able to debug using the same technique.
Related Topics
Can Inotify Tell Me Where a Monitored File Is Moved
What Exactly Is Program Stack's Growth Direction
Linux Process Context and Svc Call in Arm
Matching Third Field in a CSV with Pattern File in Gnu Linux (Awk/Sed/Grep)
Copying Files with Wildcard (*) to a Folder in a Bash Script - Why Isn't It Working
Why Can't Bash Recognize The Existence of a Socket File
How to Send Email from The Command Line
Raspberry-Pi Docker Error: Standard_Init_Linux.Go:178: Exec User Process Caused "Exec Format Error"
Running Docker Without Sudo on Ubuntu 14.04
Calculator in Assembly Language - Linux X86 & Nasm - Division
.Lis Files Generated While Compiling Pro*C Code in Linux
Bash Command Line Arguments Passed to Sed via Ssh
How to Remove Everything Else in a Folder Except Filea