我有一个多行的文件

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

如何删除第一列和“数字x”之间的“数字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    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

我想要相同的输出......而且数字总是在最后一个数字字段中

最佳答案

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

输出:

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

关于awk - 删除匹配字符后的所有字符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27211825/

10-13 08:40