如何在一列的开头和另一列的末尾添加字符串?

如何在一列的开头和另一列的末尾添加字符串?

我有一个这样的文件:

head pheno_143
FID IID CURRELIG RET_Summary new143
fam1000 G1000 1 1 1
fam1001 G1001 1 1 1
fam1003 G1003 1 2 2
fam1005 G1005 1 1 1
fam1009 G1009 1 1 1
fam1052 G1052 1 1 1
...

我想更改它的前两列,使其看起来像这样:

head pheno_143
FID IID CURRELIG RET_Summary new143
fam1000_G1000 fam1000_G1000 1 1 1
fam1001_G1001 fam1001_G1001 1 1 1
fam1003_G1003 fam1003_G1003 1 2 2
fam1005_G1005 fam1005_G1005 1 1 1
fam1009_G1009 fam1009_G1009 1 1 1
fam1052_G1052 fam1052_G1052 1 1 1
...

答案1

简单的字符串连接:

$ awk 'FNR>1 {$1 = $1 "_" $2; $2 = $1} 1' pheno_143
FID IID CURRELIG RET_Summary new143
fam1000_G1000 fam1000_G1000 1 1 1
fam1001_G1001 fam1001_G1001 1 1 1
fam1003_G1003 fam1003_G1003 1 2 2
fam1005_G1005 fam1005_G1005 1 1 1
fam1009_G1009 fam1009_G1009 1 1 1
fam1052_G1052 fam1052_G1052 1 1 1

相关内容