Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing Control Character in sed

Tags:

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?

like image 808
myahya Avatar asked Nov 01 '12 15:11

myahya


People also ask

How do you change special characters in sed?

You need to escape the special characters with a backslash \ in front of the special character. For your case, escape every special character with backslash \ .

How do you replace a variable in a file using sed?

How SED Works. In the syntax, you only need to provide a suitable “new string” name that you want to be placed with the “old string”. Of course, the old string name needs to be entered as well. Then, provide the file name in the place of “file_name” from where the old string will be found and replaced.

Which sed command is used for replacement?

Replacing all the occurrence of the pattern in a line : The substitute flag /g (global replacement) specifies the sed command to replace all the occurrences of the string in the line.


1 Answers

Try:

sed 's/^A/foo/g' file

Use Ctrl+V+A to create the ^A sequence in the above command.

like image 76
dogbane Avatar answered Sep 24 '22 09:09

dogbane