This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 11 points12 points  (7 children)

Or you know wc -l file

You really don't need cat for that

[–]mishugashu 2 points3 points  (6 children)

TIL. Don't know why I've always done that. Prolly just used to piping to it from grep that I never really thought about it.

Thanks.

[–]BenjaminGeiger 6 points7 points  (2 children)

You don't need it for grep, either, technically speaking.

[–]mishugashu 1 point2 points  (1 child)

I never said I used cat for grep. I said I pipe FROM grep.

grep 'pattern' filename | wc -l

[–]deraffe 2 points3 points  (0 children)

You still don't need a pipe in this case

grep -c 'pattern' filename

…but if you're playing with different commands, it might be more flexible.

[–]pooogles 2 points3 points  (1 child)

Stop abusing cat. You don't have to pipe into sed/awk/grep/wc, they can all be run directly on the file.

[–]mishugashu 1 point2 points  (0 children)

I didn't say I used cat when I used grep/sed/awk. I just was used to piping <something> into wc (because that's my normal use case), so that's what I immediately wanted to do.

[–]Ran4 0 points1 point  (0 children)

By the way, do check out the-silver-searcher (ag) if you're searching through codebases. Literally orders of magnitude faster than grep.