I am trying to use grep "regex" path_to_file
, and this is my approach:
grep "(\/bbcswebdav\/.*_2)" file.txt
(escaping /
is what regex101 promoted me to do)
There were no outputs in the console.
However, when I tested the regular expression on regex101, I received my desired output.
The desired results here are all strings from /bbcswebdav/
to _2
, e.g. /bbcswebdav/pid-816174-dt-content-rid-8436387_2/xid-8436387_2
But when I do
grep "/bbcswebdav/.*_2" file.txt
The same goes with grep -E
, suggested in the comments.
grep -E "/bbcswebdav/.*_2" file.txt
the output will be very messy, in this case: <li><a href="/bbcswebdav/pid-816174-dt-content-rid-8436387_2/xid-8436387_2" target="_blank"><img src="/images/ci/ng/cal_year_event.gif" alt="file"> 5 diversity-name.pptx</a>
Therefore my questions are:
- What might have gone wrong in my command line input?
- What are some better alternative regex? (or approach, in general)
Thank you.