0
votes

My linux server has a folder with all html files. I am trying to find files (names and line numbers) using the below command:

grep -rnw '/myfolder/' -e '</tr> <footer class="final-footer">' 

I know several files that contain this pattern (with a strict single space in between the </tr> and <footer class="final-footer">). However, the grep command is returning nothing.

When I search just for '<footer class="final-footer">' (without </tr> and the following single space) the grep returns correctly.

 grep -rnw '/myfolder/' -e '<footer class="final-footer">' 

I tried the above command just to check if my grep syntax is correct. But my specific requirement is to execute the first command. How exactly to do that?

Additional Info

A sample of the pattern in one of the files is this: ....International, Inc.</td></tr> <footer class="final-footer">...

1
try without the -w flag... it will add word boundary condition and perhaps there are word characters before </tr>... adding sample input (2-3 lines including the line to be matched) would help in testing..Sundeep
Hi, tried removing w flag, but no luck. A sample of the pattern in one of the files is this: ....International, Inc.</td></tr> <footer class="final-footer">...Kannan

1 Answers

1
votes

Since you know the exact string to find, you might as well use the -F option. No need to fiddle with regular expresions.

grep -Fnr '</tr> <footer class="final-footer">'  myFolder

From the man page:

-F, --fixed-strings
          Interpret PATTERN as a list of fixed strings (instead of regular expressions),
          separated by newlines, any of which is to be matched.