Wednesday, 15 February 2012

regex - find files with more than 1 match using grep -


I am thinking that there is no way to list files with more than 1 match using grep. Here's what I'm doing: I'm going through a customer's website and trying to replace the last match with a string. Therefore, at the bottom of each page, he has this line:

  & lt; P align = "center" & gt; & Lt; Font face = "aerial" color = "# 808080" size = "2" & gt;  

Which is followed by a footer, I need to change it (sed) from this line:

   

But I want to separate the files which are just 1 instance of that first line, so I can replace them. Another solution to my problem would be to use sed only on the last match, or to use sed on the last 50 lines of a file. Any ideas for me?

You can actually use grep -c in the file matches Number of:

  grep -c '& lt; P align = "center" & gt; & Lt; Font face = "arial" color = "# 808080" size = "2" & gt;   

To store your output

  cnt = $ (grep -c '& lt; p align = "center" & Gt; & lt; font face = "aerial" color = "# 808080" size = "2" & gt; 'file)  

No comments:

Post a Comment