Results 1 to 3 of 3
His,
is there an elegant way of matching only the first occurrence of a pattern and at the same time match all occurrencies of a second pattern?
the case is ...
- 11-08-2009 #1
"multiple" searches with grep, or other command
His,
is there an elegant way of matching only the first occurrence of a pattern and at the same time match all occurrencies of a second pattern?
the case is question is that i want to get only the first occurrence of "Duration", but all the occurrences of "Language":
$ mediainfo file.mkv | grep -m1 -e "Duration" -e "Language"
only returns one line with "Duration" and misses all lines with "Language" altogether...
- 11-08-2009 #2
I believe that the option "-m1" indicates to grep to return at most one match, whereas "-m2" would return two matches.
- 11-08-2009 #3
Yes you're right,
grep will stop after finding M counts when the option "-m M" is given.
and in fact i need something more elaborate. I'm writing a script to catalog my stuff, and right now i'm fighting with the .mkv format:
| grep -m1 "Duration"`
| grep -m2 "Format"`
| grep -m2 "Writing library"`
| grep -E "(Overall bit rate|Width|Height|Frame rate|Language)"
something like that is the goal
well... back to programming, i guess that's what the bash script is for


Reply With Quote