Issue
I have a file in Linux, I would like to display lines which contain a specific string in that file, how to do this?
Solution
The usual way to do this is with grep
, which uses a regex pattern to match lines:
grep 'pattern' file
Each line which matches the pattern will be output. If you want to search for fixed strings only, use grep -F 'pattern' file
. fgrep
is shorthand for grep -F
.
You can also use sed
:
sed -n '/pattern/p' file
Or awk
:
awk '/pattern/' file
Answered By - knittl Answer Checked By - Marie Seifert (WPSolving Admin)