views:

505

answers:

3

I need to replace the ascii characters SOH and STX (start of header and start of text, ascii characters 1 and 2, respectively) in some really huge text files as quickly as possible... Is sed the way to go? What does that command look like?

+5  A: 

You could use

tr "\001\002" "xy"

...to translate the ascii character 1 to x and 2 to y.

tangens
+1  A: 
sed -e y/\x01\x02/xy/ *.txt

y// is sed's transliterate command. You can use the -i switch to edit the files in-place.

Tomalak
+1  A: 

If you're replacing SOH and STX with single characters, use tr (assuming you're replacing SOH with x and STX with Y):

tr '\001\002' 'xy' <sourcefile >destfile
Uh Clem