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