Delete ^O from a text file
I have a text file which when displayed in less appears thus:
Code:
^O 3600^O 3603^O 0^O 0^O 0^O 0^O 0^O 0 In vim, I can get rid of them using :%s/^O//g where ^O = ctrl-v + ctrl-o, but I can't get the same to work in sed. I know these are null characters of some sort, I'd just like to delete them, leaving only the numbers. |
may or may not work. If not, try to use ctrl-v,ctrl-o too.
Code:
sed 's/\^O//g' file |
If they appear in inverse video in less, they are probably ASCII SI characters (decimal 15, octal 017).
You can verify this with od: Code:
$ od -ta yourfile |head -n 1 If you can verify that the characters in your file are also ASCII SI characters, you can use this command to remove them: Code:
sed 's/\o017//g' yourfile > yourfile.new |
Thanks for the responses.
I feel like a bit of a fool: having said that ctrl-v + ctrl-o worked in vim, I didn't try it directly in the CLI or using those keystrokes in my script, but it seems that it works perfectly well. In the end I went with tr: Code:
tr -d "^O" < input_file > output_file I've been looking for a way to do this sort of this for a while, specifically the od -ta command, and that's going to be useful in future! Thanks again. |
All times are GMT -5. The time now is 09:57 PM. |