Home > Net >  bash / awk : filter value from field
bash / awk : filter value from field

Time:06-10

I am trying to filter column 2 for a range of digits out of the FILEDIGITS.txt.

for i in `seq -f '%0.f\n' 66979300 100 66982300`; do
awk -v var=$i 'BEGIN{FS=OFS="\t"}{$2 == var }{print $0 }' FILEDIGITS.txt >> FILTERED.txt                        
done

Nevertheless no filtering it is happening, the FILTERED.TXT is identical to the FILEDIGITS.TXT.

I checked and the values requested are present in the column 2 of the FILEDIGITS.TXT, filtering should then happen successfully.

Where am I wrong? Many thanks for the help!

CodePudding user response:

Do you know this great page ? Awk - A Tutorial and Introduction - by Bruce Barnett - Grymoire

Give a try to this:

for i in `seq -f '%0.f\n' 66979300 100 66982300`; do
  awk 'BEGIN {FS=OFS="\t"} ; $2 == var {print $0}' var="${i}" FILEDIGITS.txt >> FILTERED.txt                        
done
  • Related