I want to remove all "^A" control characters from a file using SED. I can remove all control characters using 'sed s/[[:cntrl:]]//g' but how can I specify "^A" specifically?
Using the truncate Command. The command truncate contracts or expands a file to a given size. The truncate command with option -s -1 reduces the size of the file by one by removing the last character s from the end of the file.
To delete a line, we'll use the sed “d” command. Note that you have to declare which line to delete. Otherwise, sed will delete all the lines.
to reproduce "^A" simply press Ctrl-v Ctrl-a this will reproduce the ^A in the file
sed -i -e 's/^A/BLAH/g' testfile
the ^A
in that line is the result of me pressing Ctrl-v Ctrl-a
^A is byte 1 or \x01
so you should be able to do this:
sed 's/\x01//g'
Keep in mind that for single-byte changes, "tr" is faster than sed, although you'll have to use bash's $'..'
syntax to give it a 0x01 byte:
tr -d $'\x01'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With