Reputation: 24433
I have a 4-column CSV file:
01, cat, animal, it catches mice
How can I print only those lines containing exactly 2 characters in column 2 while also matching the pattern "/to " anywhere on that line in column 4?
Upvotes: 0
Views: 181
Reputation: 185560
You can use awk :
$ cat /tmp/l
01, cat, animal, it catches mice
02, ok, aaa, e/tomos
03, bad, qux, vb/tomos
$ awk -F"," 'length($2) == 3 && $4 ~ /\057to/' /tmp/l
02, ok, aaa, e/atmos
Upvotes: 1
Reputation: 2198
try this:
egrep "[^,]+,\s+[^,]{2},|([^,]+,\s+){3}.*/to.*" your_file
Try with this file:
01, cat, animal, it catches mice
01, ab, animal, it catches/o mice
01, ca, animal, it catches/to mice
01, cat, animal, it catches m/toice
and return:
01, ab, animal, it catches/o mice
01, ca, animal, it catches/to mice
01, cat, animal, it catches m/toice
Upvotes: 2