From b52a32dd2439c293892b72e35b57b4887a5a53cf Mon Sep 17 00:00:00 2001 From: "Gregory S. Kielian" Date: Sat, 27 Sep 2014 12:04:25 -0700 Subject: Added `sed` and `grep` examples to useful-commands --- bash.html.markdown | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'bash.html.markdown') diff --git a/bash.html.markdown b/bash.html.markdown index dc7d32b6..0f571e83 100644 --- a/bash.html.markdown +++ b/bash.html.markdown @@ -9,6 +9,7 @@ contributors: - ["akirahirose", "https://twitter.com/akirahirose"] - ["Anton Strömkvist", "http://lutic.org/"] - ["Rahil Momin", "https://github.com/iamrahil"] + - ["Gregrory Kielian", "https://github.com/gskielian"] filename: LearnBash.sh --- @@ -199,4 +200,8 @@ sort file.txt uniq -d file.txt # prints only the first column before the ',' character cut -d ',' -f 1 file.txt +# replaces every occurance of 'apples' with 'oranges' in file.txt +sed -i 's/apples/oranges/g' file.txt +# prints the number of occurances of "foo" in file.txt +grep -c "foo" file.txt ``` -- cgit v1.2.3 From e9c21740df4c93ee4575eca41b0028fa2d90ce1b Mon Sep 17 00:00:00 2001 From: "Gregory S. Kielian" Date: Sat, 27 Sep 2014 12:06:36 -0700 Subject: amended grep description --- bash.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bash.html.markdown') diff --git a/bash.html.markdown b/bash.html.markdown index 0f571e83..fd347488 100644 --- a/bash.html.markdown +++ b/bash.html.markdown @@ -202,6 +202,6 @@ uniq -d file.txt cut -d ',' -f 1 file.txt # replaces every occurance of 'apples' with 'oranges' in file.txt sed -i 's/apples/oranges/g' file.txt -# prints the number of occurances of "foo" in file.txt +# prints the number of lines with the string "foo" in file.txt grep -c "foo" file.txt ``` -- cgit v1.2.3 From d22d591e3e2120dd1bed70cd8093569c8b7101c2 Mon Sep 17 00:00:00 2001 From: "Gregory S. Kielian" Date: Sat, 27 Sep 2014 12:12:56 -0700 Subject: amended sed and bash descriptions --- bash.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bash.html.markdown') diff --git a/bash.html.markdown b/bash.html.markdown index fd347488..160fe8f2 100644 --- a/bash.html.markdown +++ b/bash.html.markdown @@ -200,8 +200,8 @@ sort file.txt uniq -d file.txt # prints only the first column before the ',' character cut -d ',' -f 1 file.txt -# replaces every occurance of 'apples' with 'oranges' in file.txt +# replaces every occurrence of 'apples' with 'oranges' in file.txt sed -i 's/apples/oranges/g' file.txt -# prints the number of lines with the string "foo" in file.txt +# prints the number of lines containing the string "foo" in file.txt grep -c "foo" file.txt ``` -- cgit v1.2.3 From d83a0f038558cf32680287417bbd692b33fe13cc Mon Sep 17 00:00:00 2001 From: "Gregory S. Kielian" Date: Sat, 4 Oct 2014 14:50:00 -0700 Subject: Changed descriptions, added grep, fgrep examples --- bash.html.markdown | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'bash.html.markdown') diff --git a/bash.html.markdown b/bash.html.markdown index 160fe8f2..9b199b8c 100644 --- a/bash.html.markdown +++ b/bash.html.markdown @@ -200,8 +200,12 @@ sort file.txt uniq -d file.txt # prints only the first column before the ',' character cut -d ',' -f 1 file.txt -# replaces every occurrence of 'apples' with 'oranges' in file.txt -sed -i 's/apples/oranges/g' file.txt -# prints the number of lines containing the string "foo" in file.txt -grep -c "foo" file.txt +# replaces every occurrence of 'okay' with 'great' in file.txt, (regex compatible) +sed -i 's/okay/great/g' file.txt +# print to stdout all lines of file.txt which match some regex, the example prints lines which beginning with "foo" and end in "bar" +grep "^foo.*bar$" file.txt +# pass the option "-c" to instead print the number of lines matching the regex +grep -c "^foo.*bar$" file.txt +# if you literally want to search for the string, and not the regex, use fgrep (or grep -F) +fgrep "^foo.*bar$" file.txt ``` -- cgit v1.2.3