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

前端 未结 2 1551
情深已故
情深已故 2021-01-12 06:10

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\" specif

相关标签:
2条回答
  • 2021-01-12 06:56

    ^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'
    
    0 讨论(0)
  • 2021-01-12 07:05

    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

    0 讨论(0)
提交回复
热议问题