LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-24-2012, 04:05 AM   #1
vixxant
LQ Newbie
 
Registered: Mar 2012
Posts: 2

Rep: Reputation: Disabled
How to remove using sed


i have a file which contains characters like the list below how can i keep the part which contains 9 numbers and delete the reset using sed.

4 223 56 78 97 1 7
1 1 14 670724549 1
696753644 98 2
901443645 3
1 36 �� 712643692 128
� 787891730 98 129
1 36 1 � 682594314 130
2 4 676794417 98 131
1 37 � 512481752 132

out put should be like
670724549
696753644
901443645
712643692

thanks
 
Old 05-24-2012, 04:53 AM   #2
tshikose
Member
 
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 525

Rep: Reputation: 95
Code:
grep -o "[0-9]\{9\}" /path/to/file
 
1 members found this post helpful.
Old 05-24-2012, 04:53 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,830

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
that is simple: replace any non-digit char to nothing
sed 's/search for non-digits/<nothing>/g' file
see man sed for exact search string
 
Old 05-24-2012, 05:19 AM   #4
vixxant
LQ Newbie
 
Registered: Mar 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Works perfectly
Code:
grep -o "[0-9]\{9\}" /path/to/file
thanks
 
  


Reply



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
remove particular characters using sed dsids Linux - Software 7 12-14-2010 12:10 AM
how to remove comments with sed igor.R Linux - Newbie 16 06-22-2009 08:38 PM
How to remove a value with sed mierdatuti Programming 3 12-18-2008 05:36 PM
help with sed to remove all text except for some Benanzo Linux - Software 7 01-04-2007 06:21 AM
Remove string in sed twantrd Programming 7 09-13-2006 02:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:46 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