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?
views:
505answers:
3
+5
A:
You could use
tr "\001\002" "xy"
...to translate the ascii character 1 to x and 2 to y.
tangens
2009-09-29 17:15:49
+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
2009-09-29 17:19:40
+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
2009-09-29 17:20:37