why the syntax error comes when i use the same command in loop in bash linux
2
0
Entering edit mode
2.4 years ago
Priya ▴ 20

hi, I am using awk to sort a tsv file with command:

awk -F "\t" '{ if(($3 => 95) && ($13 >= 95) && ($11 <= 1e-5)) { print } }' FILENAME| sort -k1,1 -k12,12gr -k11,11g -k3,3gr | sort -u -k1,1 --merge > SORTED_FILENAME

It is working fine when i used this command for sorting of my file,but when I tried to loop the same command it's giving my syntax error. the Looped command that I used is:

ls|while read i;do awk -F "\t" '{ if(($3 => 95) && ($13 >= 95) && ($11 <= 1e-5)) { print } }' $i| sort -k1,1 -k12,12gr -k11,11g -k3,3gr | sort -u -k1,1 --merge > SORTED_$i ;done

And I have tried every possible alteration I can make here like making a bash.sh script of it and then run using

bash bash.sh

or using quotes but nothing worked. kindly help me understand why this syntax error is coming then i use the same command in loop?

the error is:

awk: cmd. line:1: { if(($3 => 95) && ($13 >= 95) && ($11 <= 1e-5)) { print } }
awk: cmd. line:1:           ^ syntax error
awk: cmd. line:1: { if(($3 => 95) && ($13 >= 95) && ($11 <= 1e-5)) { print } }
awk: cmd. line:1:                 ^ syntax error
awk: cmd. line:1: { if(($3 => 95) && ($13 >= 95) && ($11 <= 1e-5)) { print } }
awk: cmd. line:1:                                                  ^ syntax error

the file I am working on looks like this:

GCF_000240185.1_ASM24018v2_genomic_04835        WP_004181470    71.605  162     46      0       1       486     1       162     1.69e-84        243     99
GCF_000240185.1_ASM24018v2_genomic_04835        WP_002912829    29.480  173     99      9       4       480     10      173     2.03e-10        54.3    98
GCF_000240185.1_ASM24018v2_genomic_04835        WP_002903719    30.000  80      56      0       238     477     84      163     7.13e-06        41.6    49
GCF_000240185.1_ASM24018v2_genomic_04835        WP_009309163    41.270  63      35      2       244     432     67      127     5.26e-05        38.9    39
GCF_000240185.1_ASM24018v2_genomic_04835        WP_002921333    27.381  84      61      0       235     486     88      171     1.13e-04        38.1    52
GCF_000240185.1_ASM24018v2_genomic_04835        WP_004180150    98.98  118     82      2       133     483     68      182     1.84e-04        99    99
GCF_000240185.1_ASM24018v2_genomic_04835        WP_074177527    99.99  101     71      1       184     486     91      188     0.007   33.1    62
GCF_000240185.1_ASM24018v2_genomic_04835        WP_049186326    27.941  68      37      2       271     456     83      144     0.050   30.4    38
GCF_000240185.1_ASM24018v2_genomic_04835        WP_032435057    21.769  147     111     3       10      441     3       148     0.089   29.6    88
GCF_000240185.1_ASM24018v2_genomic_04835        WP_223168825    29.167  48      33      1       271     414     36      82      0.10    28.9    29
awk • 795 views
ADD COMMENT
0
Entering edit mode
2.4 years ago
ATpoint 85k

It must be >=, never =>.

ADD COMMENT
0
Entering edit mode
2.4 years ago
Michael 55k
 ls|while read i;do awk -F "\t" '{ if(($3 **=>** 95) && ($13 >= 95) && ($11 <= 1e-5)) { print } }' $i| sort -k1,1 -k12,12gr -k11,11g -k3,3gr | sort -u -k1,1 --merge > SORTED_$i ;done

I think it is a simple typo: => should be >= ('greater-equal')

ADD COMMENT

Login before adding your answer.

Traffic: 1678 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6