Find the answer to your Linux question:
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 ...
  1. #1
    Just Joined! clickalot's Avatar
    Join Date
    Nov 2009
    Location
    Erlangen, Germany
    Posts
    37

    "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...

  2. #2
    Just Joined! mehorter's Avatar
    Join Date
    May 2006
    Posts
    20
    I believe that the option "-m1" indicates to grep to return at most one match, whereas "-m2" would return two matches.

  3. #3
    Just Joined! clickalot's Avatar
    Join Date
    Nov 2009
    Location
    Erlangen, Germany
    Posts
    37
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...