简体   繁体   中英

How to replace a <85> to a new line in bash script

I'm running out of idea on how to replace this character “ <85> ” to a new line (please treat this as one character only – I think this is a non-printable character).

I tried this one in my script:

cat file | awk '{gsub(”<85>”,RS);print}' > /tmp/file.txt

but didn't work.

I hope someone can help.

Thanks.

With sed : sed -e $'s/\\302\\205/\\\\n/' file > file.txt

Or awk : awk '{gsub("\\302\\205","\\n")}7'

The magic here was in converting the <85> character to octal codepoints.

I used hexdump -b on a file I manually inserted that character into.

tr '\205' '\n' <file > file.txt

tr is the transliterate command; it translates one character to another (or deletes it, or …). The version of tr on Mac OS X doesn't recognize hexadecimal escapes, so you have to use octal, and octal 205 is hex 85.

I am assuming that the file contains a single byte '\\x85' , rather than some combination of bytes that is being presented as <85> . tr is not good for recognizing multibyte sequences that need to be transliterated.

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