Creating two files out of one file

Hi members,

I have a file with lots of text like this:

asdsfkm
dfsfom['
agko
dfblml;'
afdgpk
gkopdf
HUMAN 12 L 123E 43 
HUMAN 33 L 49235 123
HUMAN 43 L  J432 234
TER
HUMAN 9 D 3245 56
HUMAN 87 D 5856N 43
HUMAN 54 D 976 56
TER 
gsdfb
sdfg hyjf gh 
dgfj jk
 

now i want to extract only the rows with HUMAN as its 1st column
for this I used :

ruby -ne 'print if /^Human/; exit if /^TER/' $line | awk 'print $1, "\t"$2,  "\t"$3, "\t"$4, "\t"$5}' >$line"new"

This is creating a file containing data from first "HUMAN" to first TER. that is :

HUMAN 12 L 123E 43 
HUMAN 33 L 49235 123
HUMAN 43 L  J432 234

But, I need to create another file which should contain another data set after first "TER" till the second "TER", That is:

HUMAN 9 D 3245 56
HUMAN 87 D 5856N 43
HUMAN 54 D 976 56

which means that all "L" in 3rd row in one file and all "D" in 3rd row in second file. And also this L and D demarcation in filename.

Thanks in advance.

Try something like this:

awk '/^HUMAN/{print > ( "set_" $3 )}' file
1 Like