LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-05-2007, 09:04 AM   #1
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
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
^O 0^O 0^O 0^O 0^O 0^O 0^O 0^O 0
^O 0^O 0^O 0^O 0^O 0^O 0^O 0^O 0
^O 0^O 0^O 0^O 0^O 0^O 0^O 0^O 0
^O 0^O 0^O 0^O 0^O 0^O 0^O 0^O 0
^O 0^O 0^O 0^O 0^O 0^O 0^O 0^O 0
^O 0^O 0^O 0^O 0^O 0^O 0^O 0^O 0
^O 0^O 0^O 0^O 0^O 0^O 0^O 0^O 0
^O 0^O 0^O 0^O 0^O 0^O 0^O 0^O 0
^O 0^O 3^O 8^O 5^O 5^O 5^O 1^O 4
^O 6^O 5^O 0^O 4^O 5^O 3^O 7^O 3
^O 7^O 3^O 2^O 2^O 3^O 4^O 3^O 3
^O 3^O 5^O 4^O 7^O 6^O 4^O 6^O 6
^O 1^O 4^O 1^O 6^O 2^O 5^O 3^O 7
^O 3^O 2^O 0^O 5^O 1^O 5^O 5^O 5
^O 2^O 1^O 3^O 1^O 5^O 3^O 4^O 3
^O 4^O 3^O 1^O 4^O 5^O 3^O 3^O 3
^O 6^O 6^O 3^O 2^O 3^O 8^O 2^O 3
^O 0^O 2^O 3^O 3^O 2^O 4^O 1^O 1
^O 3^O 2^O 1^O 2^O 0^O 4^O 1^O 2
I'd like to delete the ^O part of it in such a manner as I can do this in a script to any number of files.

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.
 
Old 12-05-2007, 09:06 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
may or may not work. If not, try to use ctrl-v,ctrl-o too.
Code:
sed 's/\^O//g' file

Last edited by ghostdog74; 12-05-2007 at 09:10 AM.
 
Old 12-05-2007, 10:25 AM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
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
0000000  si  sp   3   6   0   0  si  sp   3   6   0   3  si  sp   0  si
Here I can see that the test file I made has space, space, "3600", si, space, "3603", ...
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
Note that the \o017 is: backslash, lower case letter o, zero, one seven.

Last edited by matthewg42; 12-05-2007 at 10:26 AM.
 
Old 12-05-2007, 11:02 AM   #4
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Original Poster
Rep: Reputation: 128Reputation: 128
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
although this is part of a longer piped command.

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.
 
  


Reply

Tags
ascii, od, sed



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
delete columns 15 to 27 of a text file powah Programming 1 01-31-2007 02:03 AM
Delete the first row from a text file loopoo Linux - Newbie 2 08-15-2006 02:57 AM
delete chunks or regions from text file - help K3vin Linux - Software 3 09-26-2005 02:57 AM
Delete line from flat text file in C zaichik Programming 6 01-26-2005 06:16 PM
How to delete a line from a text file with shell script programming Bassam General 1 01-28-2004 08:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration