Kannan
Kannan

Reputation: 123

grep not matching pattern with space in html files

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">...

Upvotes: 0

Views: 227

Answers (1)

chipsbarrier
chipsbarrier

Reputation: 31

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.

Upvotes: 1

Related Questions