Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, I have an if statement in a awk script that will not execute because it generates this error: fatal: Unmatched ( or \(: /(/ for this if statement : ...
  1. #1
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714

    Awk pattern Matching Problem

    Hi,

    I have an if statement in a awk script that will not execute because it generates this error:

    fatal: Unmatched ( or \(: /(/

    for this if statement :

    if ($i ~ /\x28/)

    Now I know the problem is \x28 translates to the parenthesis "(" and causes a syntax error but I have no idea how to phrase this so I can match $i to the hex value x28.

    I search Google and found nothing, the closest I got was a Fedora book that states "You can quote any special character(but not a digit or a parenthesis) by preceding it with a backslash" - A Practical Guide to Red Hat Linux, Sobell...This quote doesn't sound to promising...

    ...Gerard4143

    So does anyone know a way around this?
    Make mine Arch Linux

  2. #2
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    If you have to use the hex value then:

    Code:
    if ($i ~ /[\x28]/)
    But why not just:

    Code:
    if ($i ~ /\(/)

  3. #3
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Quote Originally Posted by lomcevak View Post
    If you have to use the hex value then:

    Code:
    if ($i ~ /[\x28]/)
    But why not just:

    Code:
    if ($i ~ /\(/)
    Tried that...and it won't match...

    Actually my apologies...it does match but I have to put it at the beginning of the if else if statements...for it to match. I think my problem isn't so much the matching pattern - $i ~ /\(\ - as it is the length of my if else if... statements.

    ...Gerard4143
    Make mine Arch Linux

  4. #4
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    So both you ideas worked in these simple scripts....now just to figure out why its failing in the multi level if else if statement....Thanks Gerard4143

    Code:
    awk 'BEGIN {FS = "";} {for i = 1; i <= NF; ++i}{if ($i ~ /\(/) {print$i} }' filename
    
    awk 'BEGIN {FS = "";} {for i = 1; i <= NF; ++i}{if ($i ~ /[\x28]/) {print$i} }' filename
    Make mine Arch Linux

Posting Permissions

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