Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple commands inside a awk

Tags:

awk

sry opening a new thread but awk is driving me nuts! >< im trying to run a few command assignments inside a single awk but i cant get it to work please help if this is ez for u :P i can't get the syntax to work

edit: im using /bin/bash

for f in `seq $nlinpE $loopE`; 
do 

awk  -F ","'  
BEGIN {}    
'$f'  { dataI2[$f]=$2;
    dataI3[$f]=$3;
    dataI4[$f]=$4;
    noD1[$f]=$dataI1[$f];
    noD2[$f]=$dataI2[$f];
    noD3[$f]=$dataI3[$f];
    noD1i[$f]=`echo "$nlinpN1 + $dataI1"|bc -l`;
    noD2i[$f]=`echo "$nlinpN1 + $dataI2"|bc -l`;
    noD3i[$f]=`echo "$nlinpN1 + $dataI3"|bc -l`;
    }   
'${noD1i[$f]}' { 
    dataIi2[$f]=$2;
    dataIi3[$f]=$3;
    dataIi4[$f]=$4;
    }

'${noD2i[$f]}'  { 
    dataIii2[$f]=$2;
    dataIii3[$f]=$3;
    dataIii4[$f]=$4;
    }

'${noD2i[$f]}'  { 
    dataIiii2[$f]=$2;
    dataIiii3[$f]=$3;
    dataIiii4[$f]=$4;
    }
END{}                 
' <aoa_5.inp;

done

input is like:

 17,   3.22854114,  0.562598288,  0.384291202
 18,   2.96085286,  0.085116826,  0.285071939
 19,   3.40070796,   2.27838659,  0.302027524
 20,   3.20035744,  0.333615214,  0.262585849
 21,   2.85644341,  0.258691043,  0.369726121
 22,   3.73537922,    1.3267405,  0.295917094
 23,   3.69372559,   1.32601321,  0.306054831
 24,   3.28857207,   0.63199228,  0.378117412
 25,   3.27523994,  0.695856452,  0.377585977

imjust assigning variables atm, getting the number w/o commas
i get this syntax type of error:

awk: 9: unexpected character '`'
awk: 10: unexpected character '`'
awk: 11: unexpected character '`'
(standard_in) 2: syntax error
(standard_in) 2: syntax error
awk: line 1: syntax error at or near {
^C

thx

like image 583
bakabrr Avatar asked Jan 28 '26 06:01

bakabrr


1 Answers

Maybe this will help you clean up your syntax a little so we can understand what you're trying to do.

BEGIN and END blocks are optional. Ignoring patterns for the moment, an awk program might look like this.

BEGIN {
    # Things to be done before you start processing rows.
}
{
    # Things to be done for each row.
}
END {
    # Things to be done after processing the last row.
}

If you don't happen to need BEGIN or END blocks, it might look more like this.

{
    # Things to be done for each row.
}

This awk program assigns the value of $2, $3, and $4 to the variable dataI, and prints it once for each row.

{
  dataI = sprintf("%s %s %s", $2, $3, $4);
  print dataI;
}

That assignment has no effect on the values of $2, $3, and $4.

like image 181
Mike Sherrill 'Cat Recall' Avatar answered Feb 03 '26 07:02

Mike Sherrill 'Cat Recall'



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!