What is the difference between âgrep -c ^b exampleâ and âgrep ^b example| cat âÂÂnâ?
Clash Royale CLAN TAG#URR8PPP
up vote
-2
down vote
favorite
I'm trying to learn command line better and wondering what the difference between these two commands would be.
grep -c ^b example
and
grep ^b example| cat âÂÂn
grep cat
add a comment |Â
up vote
-2
down vote
favorite
I'm trying to learn command line better and wondering what the difference between these two commands would be.
grep -c ^b example
and
grep ^b example| cat âÂÂn
grep cat
2
Welcome to Unix & Linux. If you want to learn the command line, the best way is to experiment by running the commands yourself using different input files. Questions should show some research effort so I'd advise checking the relevant man pages to find out the purpose of the different options. Man pages aren't the most readable if you're new to Unix, so if you have any issues understanding it, you could edit this question to make it more specific (and useful). See How to Ask and feel free to take the tour.
â Anthony Geoghegan
Jan 12 at 21:35
(-1) Not even the same commands. Two unrelated commands.
â Isaac
Jan 12 at 22:04
Did you try running the commands?
â Sparhawk
Jan 13 at 2:12
add a comment |Â
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
I'm trying to learn command line better and wondering what the difference between these two commands would be.
grep -c ^b example
and
grep ^b example| cat âÂÂn
grep cat
I'm trying to learn command line better and wondering what the difference between these two commands would be.
grep -c ^b example
and
grep ^b example| cat âÂÂn
grep cat
edited Jan 12 at 23:47
ilkkachu
49.8k674137
49.8k674137
asked Jan 12 at 20:53
learner1992
1
1
2
Welcome to Unix & Linux. If you want to learn the command line, the best way is to experiment by running the commands yourself using different input files. Questions should show some research effort so I'd advise checking the relevant man pages to find out the purpose of the different options. Man pages aren't the most readable if you're new to Unix, so if you have any issues understanding it, you could edit this question to make it more specific (and useful). See How to Ask and feel free to take the tour.
â Anthony Geoghegan
Jan 12 at 21:35
(-1) Not even the same commands. Two unrelated commands.
â Isaac
Jan 12 at 22:04
Did you try running the commands?
â Sparhawk
Jan 13 at 2:12
add a comment |Â
2
Welcome to Unix & Linux. If you want to learn the command line, the best way is to experiment by running the commands yourself using different input files. Questions should show some research effort so I'd advise checking the relevant man pages to find out the purpose of the different options. Man pages aren't the most readable if you're new to Unix, so if you have any issues understanding it, you could edit this question to make it more specific (and useful). See How to Ask and feel free to take the tour.
â Anthony Geoghegan
Jan 12 at 21:35
(-1) Not even the same commands. Two unrelated commands.
â Isaac
Jan 12 at 22:04
Did you try running the commands?
â Sparhawk
Jan 13 at 2:12
2
2
Welcome to Unix & Linux. If you want to learn the command line, the best way is to experiment by running the commands yourself using different input files. Questions should show some research effort so I'd advise checking the relevant man pages to find out the purpose of the different options. Man pages aren't the most readable if you're new to Unix, so if you have any issues understanding it, you could edit this question to make it more specific (and useful). See How to Ask and feel free to take the tour.
â Anthony Geoghegan
Jan 12 at 21:35
Welcome to Unix & Linux. If you want to learn the command line, the best way is to experiment by running the commands yourself using different input files. Questions should show some research effort so I'd advise checking the relevant man pages to find out the purpose of the different options. Man pages aren't the most readable if you're new to Unix, so if you have any issues understanding it, you could edit this question to make it more specific (and useful). See How to Ask and feel free to take the tour.
â Anthony Geoghegan
Jan 12 at 21:35
(-1) Not even the same commands. Two unrelated commands.
â Isaac
Jan 12 at 22:04
(-1) Not even the same commands. Two unrelated commands.
â Isaac
Jan 12 at 22:04
Did you try running the commands?
â Sparhawk
Jan 13 at 2:12
Did you try running the commands?
â Sparhawk
Jan 13 at 2:12
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
0
down vote
Well, according to the manual, grep
:
searches for PATTERN in each FILE. By
default,grep
prints the matching lines.
and with the -c
flag:
-c, --count
Suppress normal output; instead print a count of matching
lines for each input file.
So, grep -c ^b example
prints the number (count) of lines matching the pattern, while grep ^b example
prints the lines themselves.
As for cat
, it's described to
concatenate files and print on the standard output
and what the -n
flag does is to:
-n, --number
number all output lines
Given the pipe and no file names, cat
reads from the pipe, so the output is the output of grep
, with line numbers added. Hence grep ^b example| cat âÂÂn
prints all matching lines, numbered.
This is different from grep -n ^b example
, where grep
adds the line numbers of the matches. grep
knows the line numbers of the original file, while cat
only sees the output of grep
and numbers the lines accordingly.
So, given the input file
$ cat example
bar
foo
basf
We have:
$ grep -c ^b example
2
$ grep ^b example |cat -n
1 bar
2 basf
$ grep -n ^b example
1:bar
3:basf
add a comment |Â
up vote
0
down vote
Ok command:
grep -c ^b example
: Output the count for matching lines for lines that begin with letterb
, andgrep ^b example | cat -n
: pass the result of the grep command to the cat command and list them with line numbers. The-n
forcescat
to list them along with lines numbers.
Example:
example.txt with content:
media sound3
media sound1
media sound2
find sound -type f -name sound[0-9] -printf 'media %fn' > file.txt
find sound -type f -name sound[0-9] -exec bash -c 'echo media bash >> file.txt' ;
find sound -type f -name sound[0-9] -exec bash -c "f=''; echo media $( basename $f) >> file.txt" ;
Result from (1):
3
Result from (2):
1 media sound3
2 media sound1
3 media sound2
Yes your right!
â George Udosen
Jan 12 at 23:56
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Well, according to the manual, grep
:
searches for PATTERN in each FILE. By
default,grep
prints the matching lines.
and with the -c
flag:
-c, --count
Suppress normal output; instead print a count of matching
lines for each input file.
So, grep -c ^b example
prints the number (count) of lines matching the pattern, while grep ^b example
prints the lines themselves.
As for cat
, it's described to
concatenate files and print on the standard output
and what the -n
flag does is to:
-n, --number
number all output lines
Given the pipe and no file names, cat
reads from the pipe, so the output is the output of grep
, with line numbers added. Hence grep ^b example| cat âÂÂn
prints all matching lines, numbered.
This is different from grep -n ^b example
, where grep
adds the line numbers of the matches. grep
knows the line numbers of the original file, while cat
only sees the output of grep
and numbers the lines accordingly.
So, given the input file
$ cat example
bar
foo
basf
We have:
$ grep -c ^b example
2
$ grep ^b example |cat -n
1 bar
2 basf
$ grep -n ^b example
1:bar
3:basf
add a comment |Â
up vote
0
down vote
Well, according to the manual, grep
:
searches for PATTERN in each FILE. By
default,grep
prints the matching lines.
and with the -c
flag:
-c, --count
Suppress normal output; instead print a count of matching
lines for each input file.
So, grep -c ^b example
prints the number (count) of lines matching the pattern, while grep ^b example
prints the lines themselves.
As for cat
, it's described to
concatenate files and print on the standard output
and what the -n
flag does is to:
-n, --number
number all output lines
Given the pipe and no file names, cat
reads from the pipe, so the output is the output of grep
, with line numbers added. Hence grep ^b example| cat âÂÂn
prints all matching lines, numbered.
This is different from grep -n ^b example
, where grep
adds the line numbers of the matches. grep
knows the line numbers of the original file, while cat
only sees the output of grep
and numbers the lines accordingly.
So, given the input file
$ cat example
bar
foo
basf
We have:
$ grep -c ^b example
2
$ grep ^b example |cat -n
1 bar
2 basf
$ grep -n ^b example
1:bar
3:basf
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Well, according to the manual, grep
:
searches for PATTERN in each FILE. By
default,grep
prints the matching lines.
and with the -c
flag:
-c, --count
Suppress normal output; instead print a count of matching
lines for each input file.
So, grep -c ^b example
prints the number (count) of lines matching the pattern, while grep ^b example
prints the lines themselves.
As for cat
, it's described to
concatenate files and print on the standard output
and what the -n
flag does is to:
-n, --number
number all output lines
Given the pipe and no file names, cat
reads from the pipe, so the output is the output of grep
, with line numbers added. Hence grep ^b example| cat âÂÂn
prints all matching lines, numbered.
This is different from grep -n ^b example
, where grep
adds the line numbers of the matches. grep
knows the line numbers of the original file, while cat
only sees the output of grep
and numbers the lines accordingly.
So, given the input file
$ cat example
bar
foo
basf
We have:
$ grep -c ^b example
2
$ grep ^b example |cat -n
1 bar
2 basf
$ grep -n ^b example
1:bar
3:basf
Well, according to the manual, grep
:
searches for PATTERN in each FILE. By
default,grep
prints the matching lines.
and with the -c
flag:
-c, --count
Suppress normal output; instead print a count of matching
lines for each input file.
So, grep -c ^b example
prints the number (count) of lines matching the pattern, while grep ^b example
prints the lines themselves.
As for cat
, it's described to
concatenate files and print on the standard output
and what the -n
flag does is to:
-n, --number
number all output lines
Given the pipe and no file names, cat
reads from the pipe, so the output is the output of grep
, with line numbers added. Hence grep ^b example| cat âÂÂn
prints all matching lines, numbered.
This is different from grep -n ^b example
, where grep
adds the line numbers of the matches. grep
knows the line numbers of the original file, while cat
only sees the output of grep
and numbers the lines accordingly.
So, given the input file
$ cat example
bar
foo
basf
We have:
$ grep -c ^b example
2
$ grep ^b example |cat -n
1 bar
2 basf
$ grep -n ^b example
1:bar
3:basf
answered Jan 12 at 23:54
ilkkachu
49.8k674137
49.8k674137
add a comment |Â
add a comment |Â
up vote
0
down vote
Ok command:
grep -c ^b example
: Output the count for matching lines for lines that begin with letterb
, andgrep ^b example | cat -n
: pass the result of the grep command to the cat command and list them with line numbers. The-n
forcescat
to list them along with lines numbers.
Example:
example.txt with content:
media sound3
media sound1
media sound2
find sound -type f -name sound[0-9] -printf 'media %fn' > file.txt
find sound -type f -name sound[0-9] -exec bash -c 'echo media bash >> file.txt' ;
find sound -type f -name sound[0-9] -exec bash -c "f=''; echo media $( basename $f) >> file.txt" ;
Result from (1):
3
Result from (2):
1 media sound3
2 media sound1
3 media sound2
Yes your right!
â George Udosen
Jan 12 at 23:56
add a comment |Â
up vote
0
down vote
Ok command:
grep -c ^b example
: Output the count for matching lines for lines that begin with letterb
, andgrep ^b example | cat -n
: pass the result of the grep command to the cat command and list them with line numbers. The-n
forcescat
to list them along with lines numbers.
Example:
example.txt with content:
media sound3
media sound1
media sound2
find sound -type f -name sound[0-9] -printf 'media %fn' > file.txt
find sound -type f -name sound[0-9] -exec bash -c 'echo media bash >> file.txt' ;
find sound -type f -name sound[0-9] -exec bash -c "f=''; echo media $( basename $f) >> file.txt" ;
Result from (1):
3
Result from (2):
1 media sound3
2 media sound1
3 media sound2
Yes your right!
â George Udosen
Jan 12 at 23:56
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Ok command:
grep -c ^b example
: Output the count for matching lines for lines that begin with letterb
, andgrep ^b example | cat -n
: pass the result of the grep command to the cat command and list them with line numbers. The-n
forcescat
to list them along with lines numbers.
Example:
example.txt with content:
media sound3
media sound1
media sound2
find sound -type f -name sound[0-9] -printf 'media %fn' > file.txt
find sound -type f -name sound[0-9] -exec bash -c 'echo media bash >> file.txt' ;
find sound -type f -name sound[0-9] -exec bash -c "f=''; echo media $( basename $f) >> file.txt" ;
Result from (1):
3
Result from (2):
1 media sound3
2 media sound1
3 media sound2
Ok command:
grep -c ^b example
: Output the count for matching lines for lines that begin with letterb
, andgrep ^b example | cat -n
: pass the result of the grep command to the cat command and list them with line numbers. The-n
forcescat
to list them along with lines numbers.
Example:
example.txt with content:
media sound3
media sound1
media sound2
find sound -type f -name sound[0-9] -printf 'media %fn' > file.txt
find sound -type f -name sound[0-9] -exec bash -c 'echo media bash >> file.txt' ;
find sound -type f -name sound[0-9] -exec bash -c "f=''; echo media $( basename $f) >> file.txt" ;
Result from (1):
3
Result from (2):
1 media sound3
2 media sound1
3 media sound2
edited Jan 12 at 23:56
answered Jan 12 at 21:14
George Udosen
1,112318
1,112318
Yes your right!
â George Udosen
Jan 12 at 23:56
add a comment |Â
Yes your right!
â George Udosen
Jan 12 at 23:56
Yes your right!
â George Udosen
Jan 12 at 23:56
Yes your right!
â George Udosen
Jan 12 at 23:56
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f416674%2fwhat-is-the-difference-between-grep-c-b-example-and-grep-b-example-cat-n%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
Welcome to Unix & Linux. If you want to learn the command line, the best way is to experiment by running the commands yourself using different input files. Questions should show some research effort so I'd advise checking the relevant man pages to find out the purpose of the different options. Man pages aren't the most readable if you're new to Unix, so if you have any issues understanding it, you could edit this question to make it more specific (and useful). See How to Ask and feel free to take the tour.
â Anthony Geoghegan
Jan 12 at 21:35
(-1) Not even the same commands. Two unrelated commands.
â Isaac
Jan 12 at 22:04
Did you try running the commands?
â Sparhawk
Jan 13 at 2:12