Difference between revisions of "Grep"
From Linuxintro
imported>ThorstenStaerk |
imported>ThorstenStaerk |
||
Line 19: | Line 19: | ||
grep -E "U" | grep -E "U" | ||
Matches all lines starting with U | Matches all lines starting with U | ||
+ | |||
+ | * Show all files containing ''content'' | ||
+ | grep -ir "''content''" * | ||
= Usecases = | = Usecases = |
Revision as of 11:45, 22 December 2009
- Show all lines that do not contain blabla
grep -v blabla filename.txt
- Match any character
With a dot (.) you can match any character
grep -E "L.nux"
Matches Linux, Lanux L nux, but not Lnux
- Match all characters
With a .* you can match an arbitrary count of any character
grep -E "L.*nux"
Matches Linux, Liinux, Lanux, L nux and Lnux
- Match any character but blank
grep -E "L[^ ]nux"
Matches Linux, Lanux, but not Lnux and not L nux
- Match any line starting with a character
grep -E "U"
Matches all lines starting with U
- Show all files containing content
grep -ir "content" *
Usecases
Show all running processes
ps auxf | grep -E "^[^ ]+ +[^ ]+ +[^ ]+ +[^ ]+ +[^ ]+ +[^ ]+ +[^ ]+ +R"