Biostar Beta. Not for public use.
Question: Running Batch Files From Command Line
0
Entering edit mode

I have around 50 similar .txt files in a folder. I extracted the info I need from txt files. I was wondering how to run all these 50 files (less *.gz.txt| awk '... doesn't create .output.txt for individual input .txt files) in a single run with individual output files?

Input files look like below:

BACP0000929|xaiA|gi|302543193|ref|ZP_07295535.1|_<97>:0:664:+  0       0.0     0.0     0.0
BACP0000011|fytD|gi|340626483|ref|YP_004744935.1|_<97>:0:657:+ 0       0.0     0.0     0.0
BACP0008288|cuyD|gi|365866299|ref|ZP_09405920.1|_<97>:0:660:+  0       0.0     0.0     0.0

Used command:

less 9673.fna.gz.txt |  awk '{OFS="\t";  split($1,x,"|"); print x[2], $2}'| awk '$2 > 0'| sort -k2r| uniq –c | sort -rn > output.txt

Output:

286 xaiA    1
236 FabB    1
170 uyTB    1
166 yuTB    1
152 iopC    1
ADD COMMENTlink 6.0 years ago bioinfo • 700
Entering edit mode
1

for i in *.txt;do cat $i | awk . . . >$(basname $i .txt).output.txt;done

ADD REPLYlink 6.0 years ago
Chris Miller
20k
Entering edit mode
1

Use GNU Parallel to parallelize:

do_one() {
  cat $1 | awk '{OFS="\t";  split($1,x,"|"); print x[2], $2}'| awk '$2 > 0'| sort -k2r| uniq –c | sort -rn 
}
export -f do_one
parallel do_one {} ">" {.}.output.txt ::: *.txt
ADD REPLYlink 6.0 years ago
ole.tange
♦ 3.4k
Entering edit mode
0

And now that I've sent you on the right track, I'm closing this question because it's really a programming question, not a bioinformatics question. You'd have better luck with stack overflow, or better yet, a basic BASH tutorial website.

ADD REPLYlink 6.0 years ago
Chris Miller
20k
This thread is not open. No new answers may be added
Similar Posts
Loading Similar Posts
Powered by the version 2.0