将两行转换为两列

将两行转换为两列

我想使用将每两行转换为两列awk

输入.txt:

# Query: gi|11465907|ref|NC_001872.1| Chlamydomonas eugametos genome, complete genome
# 0 hits found
# Query: gi|11465922|ref|NC_000892.1| Pedinomonas minor genome, complete genome
# 1 hits found

输出.txt:

Chlamydomonas eugametos genome 0
Pedinomonas minor genome 1

答案1

假设您的输入文件是一致的:

awk -F'[|,]' '/genome/ {printf "%s ", $5; next} {print substr($1,3,1)}' input.txt > output.txt
Chlamydomonas eugametos genome 0
Pedinomonas minor genome 1

答案2

尝试:

awk -F'[|] |,' '{getline p; split(p,H," "); print $2,H[2]}' file

这将依赖于|分隔字段中没有额外的逗号。

从这个意义上来说,更稳健的是:

awk -F'[|] *' '{getline p; split($5,Q,","); split(p,H," "); print Q[1],H[2]}' file

sed 的替代方案:

sed 'N; s/.*| *//; s/,.*\n#//; s/ hits found//' file

相关内容