I have a file with multiple rows, each row delimited with |
into multiple columns.
I can grep for a certain row, and I can cut for a certain column, but I can't figure out how to do both.
grep '^1001' customer
grabs rows starting with 1001, from a file named customer
cut -d "|" -f 3 customer
cuts column 3 from all the rows in customer file.
So....
grep '^1001' customer | cut -d "|" -f 3 customer
Simply omit the filename when you call cut
and it'll use the output of grep
as its input:
grep 1001 customer | cut -d "|" -f 3
It is also worth noting that grep 1001
doesn't grab rows starting with 1001; it grabs rows containing 1001.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With