Replacing Control Character in sed

后端 未结 5 1992
再見小時候
再見小時候 2020-12-01 03:29

I need to replace all occurrences of the control character CTRL+A (SOH/ascii 1) in a text file in linux, how can this be achieved in SED?

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-01 03:41

    This can be done through cat with the -v (equivalently --show-nonprinting options and piping this into sed).

    If the control character the start of heading (SOH) character (CTRL+A / ASCII 1), and we want to replace it with a tab, we would do the following:

    cat -v file | sed 's/\^A/\t/g' > out
    

    cat -v would replace the SOH character with ^A, which would then be matched and replaced in sed.

提交回复
热议问题