包含具有SED / Perl的数字字符串中删除部分 [英] Removing parts of a string that contain digit with SED/Perl

查看:114
本文介绍了包含具有SED / Perl的数字字符串中删除部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的数据:

I have a data that looks like this:

AB208804_1 446 576 AB208804_1orf 0
AB208804_20 446 576 AB208804_20orf 0

我想将它们转换成这样:

I want to convert them into this:

AB208804 446 576 AB208804orf 0
AB208804 446 576 AB208804orf 0

只是列1和4去除_ \\数字部分

just by removing _\digit part in column 1 and 4.

为什么这行不工作:

sed 's/_\d+//g'

什么是做(单行)的正确方法?

What's the correct way to do it (one-liner)?

推荐答案

您需要关于sed -r开关和字符类。

You need the -r switch and a character class for the sed.

$ echo "AB208804_1 446 576 AB208804_1orf 0" | sed -r 's/_[0-9]+//g'
AB208804 446 576 AB208804orf 0

或者,既然你问;在Perl:

Or, since you asked; in perl:

$ echo "AB208804_1 446 576 AB208804_1orf 0" | perl -ne 's/_\d+//g; print $_'
AB208804 446 576 AB208804orf 0

这篇关于包含具有SED / Perl的数字字符串中删除部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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