复制字符串结尾并粘贴到新列

时间:2017-02-08 20:40:56

标签: awk sed paste cut

我使用哪个UNIX命令复制第1列中字符串的结尾并将其粘贴到新列?

例如,

> $ head -3 test1.bed 
> HLA:HLA00001_A_01:01:01:01_3503  1 
> HLA:HLA02169_A_01:01:01:02N_3291 1 
> HLA:HLA14798_A_01:01:01:03_2903  1 

变为

> $ head -3 test1.bed 
> HLA:HLA00001_A_01:01:01:01_3503  1 3503
> HLA:HLA02169_A_01:01:01:02N_3291 1 3291
> HLA:HLA14798_A_01:01:01:03_2903  1 2903

1 个答案:

答案 0 :(得分:1)

awk救援!

$ awk '{n=split($1,a,"_"); print $0, a[n]}' file

HLA:HLA00001_A_01:01:01:01_3503  1  3503
HLA:HLA02169_A_01:01:01:02N_3291 1  3291
HLA:HLA14798_A_01:01:01:03_2903  1 2903