Linux   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了awk – 删除匹配字符后的所有字符大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我有一个包含许多行的文件 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 th
我有一个包含许多行的文件

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 – 删除匹配字符后的所有字符全部内容,希望文章能够帮你解决awk – 删除匹配字符后的所有字符所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: