匹配字符后删除所有人物 [英] Remove all character after matched character

查看:91
本文介绍了匹配字符后删除所有人物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多行的文件

  http://example.com/part-1这个号码1
http://example.com/part--2这是数两个21
http://example.com/part10这是一个数一二十种
http://example.com/part-num-11这是一个axample数212 11

我如何删除后,数字x第一columd和号X之间+ ...我想我的输出类似这样

所有的字符

  http://example.com/part-1 1
http://example.com/part--2 21
http://example.com/part10 12
http://example.com/part-num-11 212

另一种情况:
输入:

  http://server1.example.com/00/part-1这个号码1
http://server2.example.com/1a/part--2这是第21条二两
http://server3.example.com/2014/5/part10这是一个部分一二十种十十
http://server5.example.com/2014/7/part-num-11这是一个部件号212 11

我想同样的输出....和数量始终在最后数字字段


解决方案

  SED -rS / ^([^ 0-9] * [0-9] +)[^ 0-9] *([0-9] +)。* / \\ 1 \\ 2 /'文件

输出:


http://example.com/part-1 1
http://example.com/part--2 21
http://example.com/part10 12
http://example.com/part-num-11 212

I have a file with many lines

http://example.com/part-1   this    number 1 one 
http://example.com/part--2  this is number 21 two
http://example.com/part10   this is an number 12 ten
http://example.com/part-num-11  this is an axample  number 212 eleven

How can I remove all character after "number x" + between first columd and "number x"...I wanna my output like this

http://example.com/part-1    1
http://example.com/part--2   21 
http://example.com/part10    12
http://example.com/part-num-11   212 

Another case : Input:

http://server1.example.com/00/part-1    this    number 1 one 
http://server2.example.com/1a/part--2   this is section 21 two two
http://server3.example.com/2014/5/part10    this is an Part 12 ten  ten ten
http://server5.example.com/2014/7/part-num-11   this is an PARt number 212 eleven

I wanna the same output....And the number is always in last numeric field

解决方案

sed -r 's/^([^0-9]*[0-9]+)[^0-9]*([0-9]+).*/\1 \2/' file

Output:

http://example.com/part-1 1
http://example.com/part--2 21
http://example.com/part10 12
http://example.com/part-num-11 212

这篇关于匹配字符后删除所有人物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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