我有一个包含很多行的文件
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
我想要相同的输出......并且数字始终位于最后一个数字字段中
这是一种方法:
awk -F"number" '{split($1,a," ");split($2,b," ");print a[1],b[1]}' 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 '{print $1,$(NF-1)}' 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)