0

The input file:

vnic10
e1000g1
e1000g2
vnic10
blablabla888blablablabla999blabla

Output needed:(Only the numbers in each line)

10
1000 1
1000 2
10
888 999

We can do this using sed and remembered patterns. I am looking for the logic to get this done using awk/nawk and ksh commands.

tomkaith13
  • 1,717
  • 4
  • 27
  • 39

2 Answers2

2

Not the best formatting, but tr does the job

$ tr '[a-z]' ' ' < file_containing_input
    10
 1000 1
 1000 2
    10
         888            999 

Using awk:

$ awk '{ gsub(/[a-z]+/, " "); print }' file_containing_input
 10
 1000 1
 1000 2
 10
 888 999 

And one in bash (now I need to stop...)

$ while read a; do echo ${a//[a-z]/ }; done < file_containing_input
10
1000 1
1000 2
10
888 999
Fredrik Pihl
  • 44,604
  • 7
  • 83
  • 130
0

Seems like a homework, as "we can do this using sed". Actually it is simple substitute command, that substitutes any amount of non numeric chars with space.

sed -r "s/[^0-9]+/\ /g" input_file
Draco Ater
  • 20,820
  • 8
  • 62
  • 86
  • I dont think they give homework at my workplace .. .. I hope not atleast ..:). I know how to pull this one off in sed .. Can u suggest somethin using awk/ksh – tomkaith13 May 25 '11 at 20:43