NewUsr_stat
NewUsr_stat

Reputation: 2583

cycle on grep function

I have a list of entries (specifically names) stored in a file. Just as an example, the file contains the following names:

ACOT7   
ATP6V0D1    
INSIG2    
KLHL21    
.......
.......

In total there are 1600 names.

I need to extract the data associated with each specific name from a file derived from an analysis previously performed. What I usually do is (for example referring to the first name):

grep -w "ACOT7" output_analysis.txt > ACOT7.txt

So, I extract the values of ACOT7 name from the file output_analysis.txt and I store the data in the file ACOT7.txt. Since I have 1600 names, I can not type the string as above for 1600 names.

Can anyone help me please to find a quick way to do this type of work for all the 1600 names?

Upvotes: 3

Views: 554

Answers (1)

kirelagin
kirelagin

Reputation: 13616

for n in $(cat input.txt); do 
    grep -w "$n" output_analysis.txt > "$n.txt"
done

Upvotes: 3

Related Questions