My CSV file has 47 columns, and I want to select columns 36 - 47 by the values of a certain field. Starting column 36 to 47, each entry is like this: "1/1:0,297:297:99:10476,951,0"
I use the following AWK code to split this entry by ":", and check if array[3] >= 20 (the above highlighted is 297 in array[3]. If it passes the check, print out the entry to the new CSV, otherwise print out "./.". I need to print out the first 35 columns without condition.
When I run the following code in a file named awk_byDP (chmod u+x), it gives me this error:
/usr/bin/awk: syntax error at source line 6 source file ./awk_byDP context is
? <<< /usr/bin/awk: illegal statement at source line 6 source file ./awk_byDP
#!/usr/bin/awk -f
BEGIN {-F","; OFS=","}
NR <= 1 {next}
NR > 1 {
for (j=1; j<=35; j++) { printf("%s", $j) } #line 6
for (i=36; i<=47; i++) {
t=$i;
split(t,a,":")
if ( a[3]>=20 ) {
printf(“%s”, $i)
}
else {
printf(“%s”, "./.")
}
}
printf("\n")
}
awk --versionreturn anything helpful? Good luck.