Last active
January 24, 2018 16:13
-
-
Save andreasonny83/cf19a986bdfbd9b0ac4f394997b7b66c to your computer and use it in GitHub Desktop.
Bash commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-r: recursive | |
-i: ignore case sensitive | |
-w: match the full words | |
-B: prints the specified N lines before the match | |
-A: prints the specified N lines after the match | |
-C: shows N lines in both the side(before & after) of match | |
grep -r h[1-6] ./*.css | wc -l | |
grep -ir color=auto h[1-6] ./*.css | wc -l | |
# Copy file to clipboard | |
pbcopy < file.txt | |
grep -iw "is" demo_file | |
// This example is the regular grep where it is searching for “is”. | |
// When you search for “is”, without any option it will show out “is”, “his”, “this” | |
grep -B 2 "single WORD" demo_text | |
Example to show the difference between WORD and word | |
* 192.168.1.1 - single WORD | |
grep -A 3 -i "example" demo_text | |
Example to show the difference between WORD and word | |
* 192.168.1.1 - single WORD | |
* 192.168.1.1 - seven words. | |
grep -C 2 "Example" demo_text | |
word - word consists of a sequence of letters, digits and underscores. | |
Example to show the difference between WORD and word | |
* 192.168.1.1 - single WORD | |
Highlighting the search using GREP_OPTIONS | |
As grep prints out lines from the file by the pattern / string you had given, if you wanted it to highlight which part matches the line, then you need to follow the following way. | |
When you do the following export you will get the highlighting of the matched searches. In the following example, it will highlight all the this when you set the GREP_OPTIONS environment variable as shown below. | |
$ export GREP_OPTIONS='--color=auto' GREP_COLOR='100;8' | |
$ grep this demo_file | |
this line is the 1st lower case line in this file. | |
Two lines above this line is empty. | |
And this is the last line. | |
Pipes | |
Pipes let you use (very simple, I insist) the output of a program as the input of another one | |
ls -l | sed -e "s/[aeio]/u/g" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment