为文件中的每2行创建一个新文件

问题描述 投票:-1回答:1

我尝试读取文件并每2行创建一个新文件。新文件应保存在其他目录中。第一行应该是文件名,第二行应该是文件中的字符串。

输入文件看起来像这样:

>sample1
abcdefg
>sample2
xyz
>sample_n...
string_n...

我尝试使用以下awk命令

awk -v FS="\t" '$1 ~ />/ { file = $2 } { print $0 > /new_folder/new_file }' input_file

但是它不起作用。有什么建议吗?

bash unix bioinformatics
1个回答
0
投票

OP不包括示例输出,但是从awk尝试的解决方案中看起来如下所示>>

  • 输入行以'> \ t'开头指定文件名
  • 其他行应写入最后指定的名称
  • 所有文件应放在单独的文件夹中
awk -v 'FS=\t' -v 'dir=new_folder' '
$1 == ">" { if (new_file ) close (new_file) ; new_file = dir "/" $2 ; next }
{ print $0 > new_file }
'
© www.soinside.com 2019 - 2024. All rights reserved.