0

I have input.txt file (with 4 lines)like this:

GGTAACC_MIR4095P   USP7    MKRN1   TSHZ3   EIF2C1  SRSF8   CAMK2G      ARID4B
GCM_TINF2            MORF4L1 ABHD16A ZNF274  C7orf43 SNX33
chr9q34         MRPL41  OR5C1   LOC138159       GBGT1
REACTOME_SIGNALING_BY_NOTCH1            HDAC6   HDAC5   MAMLD1 

How to split this file into 4 files (my original file has 39 lines) so that I get 4 files each named by the first word in a line: GGTAACC_MIR4095P.txt GCM_TINF2.txt chr9q34.txt REACTOME_SIGNALING_BY_NOTCH1.txt

What I tried so far is this:

split -d -a 2 -l 1 input.txt output_

This is very far from the solution I need.

The solution per advice of @steeldriver is :

awk -F " " '{print >$1".txt"}' input.txt
2

2 Answers 2

1

with Miller (https://github.com/johnkerl/miller) using

mlr --nidx --ifs ' ' --repifs unsparsify then put -q 'tee > $1.".txt", $*' input.txt

you will have this four files:

chr9q34.txt
GCM_TINF2.txt
GGTAACC_MIR4095P.txt
REACTOME_SIGNALING_BY_NOTCH1.txt
0

Kindly use below command to achieve testes and worked fine

count=`wc -l filename| awk '{print $1}'`
praveen@praveen:~$
praveen@praveen:~$ for ((i=1;i<=$count;i++)); do j=`sed -n ''$i'p' filename`;awk -v i="$i" 'NR == i {print $0}' filename >$j.txt;done
praveen@praveen:~$ 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .