Question: Multiple commands in a for loop
0
gravatar for lamia_203
9 months ago by
lamia_20380
lamia_20380 wrote:

Hi, I am trying to make multiple commands within a for loop but it is not working as awk appears as plink.awk once pasted on the shell. I've written the command below. I have attempted to pipe is as I do not need intermediate files. Any help would be much appreciated, thank you!

for f *.linear; do 
paste $f <(yes $f | head -n $(cat $f | wc -l)) > $f.new |
awk 'NR==FNR{a[$2]=$6;next}{$10=a[$2]; print}' filtered.bim  $f.new > $f.A2 |
awk 'NR==1{print $1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" A2" ;next}{print}' $f.A2 > $f.A22 | 
awk '{ print $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $1}' $f.A22 > $f.chrbp |
awk '{print $1":"$3"\t"$11" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" "$10}' $f.chrbp > $f.2 
done
bash unix sequence loops genome • 161 views
ADD COMMENTlink modified 9 months ago • written 9 months ago by lamia_20380

may be you want to remove all those '|' at the end of the lines....

ADD REPLYlink written 9 months ago by Pierre Lindenbaum131k

And replace with ;.

ADD REPLYlink written 9 months ago by genomax91k

Thank you that has worked, but awk still appears with 'plink.awk' so I still have to edit commans once pasted on the shell. All my file names start with plink. but I'm not sure why the attach to the awk command.

ADD REPLYlink written 9 months ago by lamia_20380

This is not how piping works. Either you send things to stdout into the next command via | or you capture the output of every line with > to a file. Both is not possible at the same time.

ADD REPLYlink written 9 months ago by ATpoint40k

I'll take note thank you. It worked with the semi-colon but still produces outputs. I wanted to carry the amended file each command carries out onto the next command and avoid using the origin file each time as well as producing those files in the shell but it looks like the latter occurred.

ADD REPLYlink written 9 months ago by lamia_20380
Please log in to add an answer.

Help
Access

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