grep - awk - assign variables from multiple sources -
grep - awk - assign variables from multiple sources -
i want print output combination of multiple file content.
example:
grep -v 'word' file_a | awk -v var1="string1" -v var2="string2" -v var3="string3" '{ print $1 var1 var2 var3}' i can command above: assign specific strings variables , print grep'ed content. if string1/2/3's long it's quite complicated assign such long words.
question:
if write string1/2/3 single lines file_b how can assign such file_b lines variables?
example:
cat file_b string1 string2 string3
why not set in awk script instead of variables:
$ cat script.awk !/word/ { var1="string1" var2="string2" var3="string3longlonglonglonglonglong" print $1,var1,var2,var3 } $ cat file word no match match1 word no match match2 match 123 $ awk -f script.awk file match1 string1 string2 string3longlonglonglonglonglong match2 string1 string2 string3longlonglonglonglonglong you never need combine grep , awk.
awk grep
Comments
Post a Comment