Tuesday, November 4, 2014

Process Multivariables w/ read and a while Loop

To process data that requires you to pull multiple segments into variables, instead of a nested for loop or additional statements that would be clumsy and "awkward" (in a non-awk way) you can use a while loop and break the data into fields using awk or cut or your favorite method and read the data straight into variables:      

while read a b; do ((! $(grep -c "$a.*$b" File2.txt))) && (echo "$a $b" >> missing_pkgs.txt); done < <(awk '/>=/{ print $1" "$3 }' File1.txt)

No comments:

Post a Comment