Quantcast
Channel: Parse file with Awk only when first row matches pattern - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 4

Answer by Archemar for Parse file with Awk only when first row matches pattern

$
0
0

to list files:

try

awk 'FNR == 1 && $4 == "whatever" { print FILENAME ;}' file1 ... filen |

which will select all file having whatever in fouth colum.

If you have funny name, just add quotes.

awk 'FNR == 1 && $4 == "whatever" { printf "\"s\"\n", FILENAME ;}' file1 ... filen |

to process one file

awk 'NR == 1 && $4 != "whatever" { exit ;}  other patterns { other action;}' file

to process many file

awk 'NR == 1 && $4 != "whatever" { nextfile ;}  other patterns { other action;}' file1 ... filen

which could be read as

  • IF (condition not met) NR == 1 && $4 != "whatever"
  • THEN skip this this file { nextfile ;}
  • ELSE proceed other patterns { other action;}

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>