复制字符串末尾并粘贴到新列 [英] Copy end of string and paste to new column

查看:47
本文介绍了复制字符串末尾并粘贴到新列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Which UNIX command do I use to copy the end of a string in column 1 and paste it to a new column?

例如,

> $ 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

推荐答案

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

这篇关于复制字符串末尾并粘贴到新列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆