Reputation: 1215
I'm trying to grep and cut using pipes.
file:
c1 c2
e1 e2
e3 e4
this file has space-separated values, but when I execute
cut -f2 -d' ' | grep "e2" example.csv
output is e1 e2
the output should be e2
but I'm not sure if the cut
takes input in some other format, in the man pages it says that file name if unspecified then input would be taken.
Upvotes: 1
Views: 350
Reputation: 241818
You have it backwards. The output of cut
must be sent to grep
.
cut -f2 -d' ' example.csv | grep e2
Otherwise, grep
operates on the file, not on its input, and cut
operates on the standard input, which is coming from the outer context, probably your keyboard?
The pipeline takes the output of the left hand side command and connects it to the input of the right hand side one, not the other way round. The left hand side command doesn't know what the arguments of the right hand side command are (and vice versa).
Upvotes: 3
Reputation: 12347
Use your input file as an argument to cut
:
cut -f2 -d' ' example.csv | grep "e2"
Upvotes: 1