简体   繁体   中英

Replacing specific non-printable characters in huge files from linux command line

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?

You could use

tr "\001\002" "xy"

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

如果要用单个字符替换SOH和STX,请使用tr(假设要用x替换SOH和用Y替换STX):

tr '\001\002' 'xy' <sourcefile >destfile
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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM