I have a file:
AA BB CC DD
BB CC DD AA
BB CC DDA AA
CC DD AA BB
This command prints the line:
$ awk '{if($3=="DD") print}' file
BB CC DD AA
I want this condition to write to the array. This command does not work:
$ awk '{if($3=="DD") split($0, a, RS); print a[1]}' file
BB CC DD AA
BB CC DD AA
BB CC DD AA
Thank you for your help.
EDIT:
I wanted to write to an array of lines from the pattern ‘DD’.
These are good solutions:
awk '{if($3=="DD") {split($0, a, RS); print a[1];}}' file
awk '$3=="DD"{split($0, a, RS); print a[1];}' file
Thank you for your help.
You’re printing the result regardless of whether
$3 == "DD", which seems unlikely to be what you want.You’re also splitting with
RSwhich is not set here so for sample output, compare:which splits with
FSinstead (hence prints justBBfor the above).