I am trying to match the pattern "SHM" in a file containing like the below information and print the word matching the pattern.
LOCALZONE01 ASHM001002003VOL01
BSHM001002003VOL02
CSHM001002003VOL03
DSHM001002003VOL03_DUP
ESHM001002003VOL04
FSHM001002003VOL05
GSHM001002003VOL06_
HSHM001002003VOL07
I have tried to use awk to print the 2nd column:
grep "SHM" <filename.txt> | awk -F" " '{print $2}'
ASHM001002003VOL01
If I try to print column 1, it’s giving me the below output:
LOCALZONE01
BSHM001002003VOL02
CSHM001002003VOL03
DSHM001002003VOL03_DUP
ESHM001002003VOL04
FSHM001002003VOL05
GSHM001002003VOL06_
HSHM001002003VOL07
Below is my desired output. How can I get it?
ASHM001002003VOL01
BSHM001002003VOL02
CSHM001002003VOL03
DSHM001002003VOL03_DUP
ESHM001002003VOL04
FSHM001002003VOL05
GSHM001002003VOL06_
HSHM001002003VOL07
printf '%s\n' ASHM001002003VOL01 BSHM001002003VOL02 CSHM001002003VOL03 DSHM001002003VOL03_DUP ESHM001002003VOL04 FSHM001002003VOL05 GSHM001002003VOL06_ HSHM001002003VOL07
, because you say “a file containing below information” and not “a file containing information like the below”; i.e., you make it sound like the data in the question is the data you want to process, and not just an example. … (Cont’d) – G-Man Says 'Reinstate Monica' Sep 14 '18 at 18:20SHM
? (If so, why even bother stating that as a factor in the question?) Will the first line always have two words? If so, will the first word always beLOCALZONE01
? Will it always be 11 characters long? Will it always be followed by 5 blanks? Will the second word always start at the 17th character position? … (Cont’d) – G-Man Says 'Reinstate Monica' Sep 14 '18 at 18:21QSHM003.14159PIES
, do you want to see that entire string, or justQSHM003
(because the.
is a word separator, and so14159PIES
is a separate word)? … (Cont’d) – G-Man Says 'Reinstate Monica' Sep 14 '18 at 18:21