I have a file like the following
我有一个像下面这样的文件
Columns are delimited by tabs
列由制表符分隔
Group1 name1:ENSG0365 name4:ENSMU0000196 name2:ENSMU00001826
Group2 name2:ENS000132622 name4:ENSUS00074793
Group3 name3:ENSFP000844 name1:ENSMU000025
I want a list of files for every line, named after the 1st Column (Group1, Group2, etc) and looking like this
我想要每行的文件列表,以第1列(Group1,Group2等)命名并且看起来像这样
name1:ENSG0365
name4:ENSMU0000196
mouse2:ENSMU00001826
name1:ENSG0365 name4:ENSMU0000196 mouse2:ENSMU00001826
I don't know which tools is better for this task. Thanks for your help.
我不知道哪个工具更适合这项任务。谢谢你的帮助。
2 个解决方案
#1
1
With bash 4:
用bash 4:
while read -r name rest; do echo "$rest" >"$name"; done </path/to/your/file
Update:
更新:
while read -r name rest; do printf "%s\n" $rest >"$name"; done < /path/to/your/file
#2
1
perl -n -e '@x=split;open(F,">".shift(@x));$,="\n";print F @x' < groups.txt
Taking a wild guess at what you mean in the comment, you could try:
对评论中的含义进行疯狂猜测,您可以尝试:
perl -n -e '@x=split /\t/;open(F,">".shift(@x));$,="\n";print F @x' < groups.txt
#1
1
With bash 4:
用bash 4:
while read -r name rest; do echo "$rest" >"$name"; done </path/to/your/file
Update:
更新:
while read -r name rest; do printf "%s\n" $rest >"$name"; done < /path/to/your/file
#2
1
perl -n -e '@x=split;open(F,">".shift(@x));$,="\n";print F @x' < groups.txt
Taking a wild guess at what you mean in the comment, you could try:
对评论中的含义进行疯狂猜测,您可以尝试:
perl -n -e '@x=split /\t/;open(F,">".shift(@x));$,="\n";print F @x' < groups.txt