Hot answers tagged

3

If I understood correctly: you want to count how many times there is "P2" anywhere within the 6th field of lines 4,55 and 77 of a few files (named *h3)? You could do this with 1 awk: awk ' ( FNR==4 || FNR==55 || FNR==77 ) { if ( $6 ~ "P2" ) { occurence++ } } END { printf "There was: %d P2 ", occurence printf " among the 6th field on lines ...


2

Sure. Here's one way p2_count=0 for f in *h3; do for ((n=1; n<=77; n++)); do IFS= read -r line if [[ $n == 4|55|77 ]]; then echo "$line" set -f set -- $line set +f if [[ $6 == *P2* ]]; then ((p2_count++)) fi fi done < "$f" done > ...



Only top voted, non community-wiki answers of a minimum length are eligible