views:

54

answers:

5
first file of information page
name/joe/salary1    50  10  2
name/don/miles2
                   20   4   3
name/sam/lb3        0   200 50

can some one please tell me how can I remove all the words in the above file, so my output will looks as follows

    50  10  2

    20  4   3
    0   200 50
+1  A: 

Looks like you want to preserve only the digits and the space. If yes, you can do:

sed 's/[^0-9 ]//g' inputFile

EDIT: Change in requirements, if a digit is found with a letter, it should be treated as part of the word.

This Perl script does it:

perl -ne 's/(?:\d*[a-z\/]+\d*)*//g;print' input
codaddict
This doesn't work with `salary1`, `miles2` or `lb3` which contain digits
mouviciel
Thanks a lot for your quick respond. your cord works perfectly, but what if the those words ends with a digit as well. (as indicated above). then my final file will have those 1 2 3 in it too.
+1  A: 

sed -e "s/[a-zA-Z/]/ /g" file

will do it, though I like codaddict's way more if you want to preserver number and whitespace. This way strips out all letters and the '/' symbol, replacing them all with space.

If you want to modify the file in place, pass the -i switch. This command will output what the file would look like.

birryree
Thanks a lot for your quick respond. your cord works perfectly, but what if the those words ends with a digit as well. (as indicated above). then my final file will have those 1 2 3 in it too.
+2  A: 

Use awk instead. The following code says to go through each field, check if its an integer. If it is, print them out. No need complicated regex.

$ awk '{for(i=1;i<=NF;i++) if($i+0==$i) {printf $i" "} print ""}'  file

50 10 2

20 4 3
0 200 50
ghostdog74
Thanks a lot, it worked nicely.
A: 

If your file has this structure, I suggest first to filter out the first line, then remove all characters from beginning of line up to the first space:

sed -ni '2,$s/^[^ ]*//p' file
mouviciel
Thanks a lot for the nice explanation
A: 

Remove everything on each line until first space character (also removes leading spaces):

sed 's/\S*\s*//' file
hluk
Thanks for all of your code informations. they all worked fine.