How to remove CTRL-A characters from a file using SED?

I want to remove all control characters "^ A" from the file using SED. I can remove all control characters using 'sed s / [[: cntrl:]] // g', but how can I specifically specify "^ A"?

+7
source share
2 answers

to play "^ A" just press Ctrl-v Ctrl-a, this will play ^ A in the file

sed -i -e 's/^A/BLAH/g' testfile 

the ^A on this line is the result of pressing Ctrl-v Ctrl-a

+10
source

^ A is byte 1 or \x01 so you can do this:

 sed 's/\x01//g' 

Keep in mind that for single-byte changes, "tr" is faster than sed, although you will have to use the bash $'..' syntax to give it 0x01 bytes:

 tr -d $'\x01' 
+9
source

All Articles