This week I did only a short post, I have a lot on my plate but wanted to keep the habit of writing These during my weekly train rides.
Anyway, I had to use grep today and realized that I had forgotten the parameters a bit. So here is a little refresher:
-v : Flips what the output grep will show you. If you search for lines that contain the word test just write:
grep "test"
If you want all the lines that don't contain the word test just use the -v Parameter.
grep -v "test"
-n : shows Line numbers
-r : searches the current directory and all subdirectories recursively
--include : useful if you want Limit your search to a certain file pattern or Type.
grep --include="pom.xml" "java.version"
Or
grep --include="*.txt" "Test"
Which searches in all txt files for lines containing the word test.
To save me some typing when need to search through my files for specific terms i have a function in my bash.rc:
function grin() {
grep -r -n --include="$1" "$2"
}
So when i want to search my Java Project for all XML files containing the term java.version i just type:
grin "*.xml" "java.version"
Top comments (2)
lol I like that you called it
grin
Beeing a bit silly helps, when the day gets annoying. ;-)