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
anikaM
  • 177
  • 1
  • 10
  • Related: [Extract data from a file and place in different files based on1 column value](https://unix.stackexchange.com/questions/114061/extract-data-from-a-file-and-place-in-different-files-based-on1-column-value) – steeldriver Apr 12 '19 at 21:04
  • Thank you so much!!! That indeed solved my problem, I will post the solution above. – anikaM Apr 12 '19 at 21:14

2 Answers2

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
aborruso
  • 2,618
  • 10
  • 26
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:~$ 
Praveen Kumar BS
  • 5,139
  • 2
  • 9
  • 14