Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2004
    Posts
    45

    Unanswered: shell script for pattern matching

    I am looking for a case statement pattern matching on a unix comment line.

    For eg. given input in a file,
    #aa=1
    b=2
    c=3
    #ddd=4

    so, the comment lines needs to be skipped while reading.

    case "$line" in
    aa) do_something;;
    b) do_something;;
    c) do_something;;
    ddd) do_something;;
    #) ;; /*NOT WORKING!! */
    *) invalid input;;
    esac

    I tried couple of patterns but not working.

    Thanks.

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    It might help if you give an idea what the "do something" is.
    Do the # lines get ignored?
    Does the "aa" have to be at the start?
    Does it matter what order you do the "somethings" in?

  3. #3
    Join Date
    Jul 2004
    Posts
    45
    Quote Originally Posted by mike_bike_kite
    It might help if you give an idea what the "do something" is.
    Do the # lines get ignored?
    Does the "aa" have to be at the start?
    Does it matter what order you do the "somethings" in?
    All I want is comment lines (starts with #) need to be ignored. There is no certain order. Thanks.

  4. #4
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool grep'em

    maybe something like this:
    Code:
    while read line
    do
      case "$line" in
        aa*) do_something;;
         b*) do_something;;
         c*) do_something;;
       ddd*) do_something;;
        \#*) echo "this is a remark";;
          *) echo "invalid input";;
      esac
    done
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  5. #5
    Join Date
    Jul 2004
    Posts
    45
    Quote Originally Posted by LKBrwn_DBA
    maybe something like this:
    Code:
    while read line
    do
      case "$line" in
        aa*) do_something;;
         b*) do_something;;
         c*) do_something;;
       ddd*) do_something;;
        \#*) echo "this is a remark";;
          *) echo "invalid input";;
      esac
    done
    \#*) echo "this is a remark";;
    WORKED! Thank you very much.

Posting Permissions

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