使用grep命令匹配特定字符串后打印行

时间:2014-10-08 17:31:56

标签: unix terminal grep ubuntu-12.04

我想在匹配字符串后打印完整的行

例如,我有这样的输入: -

  www.google.com/images
  www.google.com/images/12
  www.yahoo.com/images/12
  www.bing.com/images/34
  www.google.com/images/12
  www.google.com/images/imagescols

我想要这个输出: -

 com/images              
 com/images/12           
 com/images/12           
 com/images/34           
 com/images/12           
 com/images/imagescols   

请使用unix中的grep命令建议一种方法。

1 个答案:

答案 0 :(得分:3)

您可以尝试以下剪切命令。

cut -d. -f3 file

OR

awk -F. '{print $NF}' file

OR

grep -oE '[^.]*$' file

示例:

$ cut -d. -f3 file
com/images
com/images/12
com/images/12
com/images/34
com/images/12
com/images/imagescols