Reading numbers from a text line in bash shell -


I am trying to write a Bash shell script, which is a fixed file CATALOG.dat Opens the following lines, which are made of both letters and numbers:

  event_0133_pk.gz event_0291_pk.gz event_0298_pk.gz event_0356_pk.gz event_0501_pk.gz event_0501_pk.gz  

What I want to do is print numbers (numbers only) inside a new file, using something like NUMBERS.dat & gt; ./NUMBERS.dat , to get:

  0133 02 9 02 02 0356 0501  

My problem is: I have numbers How to remove text lines? Can the script be read only in the form of a number of variables, such as event_0% d_pk.gz C / C ++?

a grep solution:

  Grep -oP '[0-9] +' CATALOG.dat & gt; Number.dat  

a sed solution:

  sed 's / [^ 0- 9] // g' catalog Dat & gt; NUMBERS.dat  

and a awk solution:

  awk -F "[^ 0-9] +" '{ Print $ 2} 'CATALOG.dat & gt; NUMBERS.dat  

Comments