我想用第 3 列中的字符串替换第二列中间的 "."。
输入文件(制表符分隔):
0 AAAAAAAAGTTT.TATAGTAATATA T x HPNK_05032012_new.fna
1 AAAAAAACGACG.ATTTTACAATAC C x HPNK_05032012_new.fna
2 AAAAAAAGCAGG.CATTATCGCTGG G x HPNK_05032012_new.fna
3 AAAAAAAGGAAC.GTGGAACGTTGG A x HPNK_05032012_new.fna
5 AAAAAACACAAC.ATTGAGCAACTT A x HPNK_05032012_new.fna
6 AAAAAACACCCA.CTGTGAAAGAAA T x HPNK_05032012_new.fna
9 AAAAAACGCCAA.GTCAGCTACAAA C x HPNK_05032012_new.fna
期望输出:
0 AAAAAAAAGTTTTTATAGTAATATA T x HPNK_05032012_new.fna
1 AAAAAAACGACGCATTTTACAATAC C x HPNK_05032012_new.fna
2 AAAAAAAGCAGGGCATTATCGCTGG G x HPNK_05032012_new.fna
3 AAAAAAAGGAACAGTGGAACGTTGG A x HPNK_05032012_new.fna
5 AAAAAACACAACAATTGAGCAACTT A x HPNK_05032012_new.fna
6 AAAAAACACCCATCTGTGAAAGAAA T x HPNK_05032012_new.fna
9 AAAAAACGCCAACGTCAGCTACAAA C x HPNK_05032012_new.fna
使用:
$ awk '{sub(".", $3, $2)}1' file
0 AAAAAAAAGTTTTTATAGTAATATA T x HPNK_05032012_new.fna
1 AAAAAAACGACGCATTTTACAATAC C x HPNK_05032012_new.fna
2 AAAAAAAGCAGGGCATTATCGCTGG G x HPNK_05032012_new.fna
3 AAAAAAAGGAACAGTGGAACGTTGG A x HPNK_05032012_new.fna
5 AAAAAACACAACAATTGAGCAACTT A x HPNK_05032012_new.fna
6 AAAAAACACCCATCTGTGAAAGAAA T x HPNK_05032012_new.fna
9 AAAAAACGCCAACGTCAGCTACAAA C x HPNK_05032012_new.fna
它基本上是使用 sub()
函数将.
替换为第 3 个字段。然后1
执行 awk 的默认行为:{print $0}
。
由于您的问题在列之间显示空格,因此我的输出仅显示一个空格。如果您的输入使用制表符,请将制表符添加为字段分隔符:
awk 'BEGIN{FS=OFS="t"} {sub(".", $3, $2)}1' file
perl -lane '$F[1] =~ s/[.]/$F[2]/; print "@F"' file
或更短,
perl -ape 's/[.]/$F[2]/' file
使用 awk,它将保持原始格式
awk '$19=$33' FS="" OFS="" file