awk - How to save each line in a text file as new file -
i have tab delimited text file 5 columns, , i'd each row own txt file contains information columns 2-5 , named after column 1.
for example, txt file has hundreds of rows similar this:
sample1name_oligos primer forwardseq reverseseq sample1name
sample2name_oligos primer forwardseq reverseseq sample2name
i'd have txt file named sample1name_oligos this:
primer forwardseq reverseseq sample1name
and txt file named sample1name_oligos looks this:
primer forwardseq reverseseq sample1name
i've tried 2 ways:
1. found thought solution:
awk '{print substr($0,match($0,$2)) >> ( $1 ".txt" )}' filename
this worked test file made (5 rows), when run on 100+ rows file first 17 files out , error:
awk: file18.txt makes many open files input record number 18, file myfile.txt source line number 1
i deleted row 18 , retried , got same error. deleted first 20 lines , retried , got same error.
2. same link, tried
cat myfile.txt | while read line; echo $line > "$line.txt"; done.
this made file each row looked this:
sample1name_oligos primer forwardseq reverseseq sample1name
and file named:
sample1name_oligos primer forwardseq reverseseq sample1name.
i'm not sure go here. i'd appreciate help. if it's not obvious, have little terminal experience i'd appreciate answers explain i'm missing.
bonnie
awk -f'\t' '$1!=prev{close(out); out=$1".txt"; prev=$1} {sub(/[^\t]+\t/,""); print > out}' file
Comments
Post a Comment