Question: (Closed) awk command in shell script
1
gravatar for mittu1602
9 months ago by
mittu1602150
India
mittu1602150 wrote:

I have an awk command which runs well on terminal: this awk command creates diffrent file according to their column header. awk command:

for((i=2;i<5;i++)); do awk -v i=$i 'BEGIN{OFS=FS="\t"}NR==1{n=$i}{print $1,$i > n".txt"}' ${Batch}.result.txt; done

the same command when incorporated in a shell script shows error:

Syntax error: Bad for loop variable
linux shell awk • 636 views
ADD COMMENTlink modified 9 months ago by Pierre Lindenbaum111k • written 9 months ago by mittu1602150
1

Are you sure that you are executing your script with bash and not sh or dash? The latter don't like some of the bash syntax.

ADD REPLYlink written 9 months ago by kloetzl960
1

please post output from echo $SHELL

ADD REPLYlink written 9 months ago by cpad01128.3k
1

Since you're using my answer from your other thread, could you please go mark it as the accepted answer?

ADD REPLYlink written 9 months ago by 5heikki7.5k

Hi, I have already accepted the answer. Thank you 😊

ADD REPLYlink written 9 months ago by mittu1602150

Hello mittu1602!

We believe that this post does not fit the main topic of this site.

sorry, I should have flagged this before instead of answering ; this post is not related to bioinformatics; It's just related to linux

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

ADD REPLYlink written 9 months ago by Pierre Lindenbaum111k
1
gravatar for Pierre Lindenbaum
9 months ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum111k wrote:

i suppose you bash is sh:

$ sh
$ for((i=2;i<5;i++));  do echo $i ; done
sh: 1: Syntax error: Bad for loop variable

while it should be bash

$ bash
$ for((i=2;i<5;i++));  do echo $i ; done
2
3
4

add a shebang at the start of your script and make it executable with chmod +x

ADD COMMENTlink modified 9 months ago • written 9 months ago by Pierre Lindenbaum111k
1

Alternatively

for i in $(seq 2 4); do ..; done

or

for i in 2 3 4; do ..; done

OP is probably using Ubuntu so his sh points to dash instead of bash

ADD REPLYlink modified 9 months ago • written 9 months ago by 5heikki7.5k
Please log in to add an answer.
The thread is closed. No new answers may be added.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 573 users visited in the last hour