I want to use awk to match where field 3 contains a number within string - then print the line and just the number as a new field.
The source file is pipe delimited and looks something like
This works with the English description of the desired output, but doesn't preserve the space between strings of digits as shown in the last line of the desired output. To get the desired output, one could use:
gsub(/[^[:digit:] ]/,X,Q)
if only <space> characters are to be allowed between strings of digits, or:
gsub(/[^[:digit:][:space:]]/,X,Q)
if any combinations of <space> and <tab> characters are to be allowed (as assumed by Ravinder's following sub() statements to get rid of leading and trailing space class characters.
after getting rid of alphabetic and punctuation class characters only removes one leading whitespace character (when it seems that there could be more than one). And, both of these could be replaced by a single gsub() call:
gsub(/^[[:space:]]+|[[:space:]]+$/,X,Q);
or, if only space characters are to be allowed between digit strings: