LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to remove using sed (http://www.linuxquestions.org/questions/linux-newbie-8/how-to-remove-using-sed-946587/)

vixxant 05-24-2012 04:05 AM

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

tshikose 05-24-2012 04:53 AM

Code:

grep -o "[0-9]\{9\}" /path/to/file

pan64 05-24-2012 04:53 AM

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

vixxant 05-24-2012 05:19 AM

Works perfectly
Code:

grep -o "[0-9]\{9\}" /path/to/file
thanks


All times are GMT -5. The time now is 05:53 PM.