quote problem in awk

Posted on 2006-04-14
Last Modified: 2010-04-22
i get unmatch problem in awk

cat file| awk ' { if($0 ~/^val=track/) { print "/bin/awk '{ print $4 ; exit 0 }'" } else { print $2 } }'

the problem is due to the awk quote in the if block ("/bin/awk '=> this quote cause the crash)

even if i place a back slash before (i.e /bin/awk \') it stays the same problem

so could u help me
Question by:laes_
    LVL 29

    Expert Comment


    Use two single quotes:

    cat file| awk ' { if($0 ~/^val=track/) { print "/bin/awk ''{ print $4 ; exit 0 }''" } else { print $2 } }'

    LVL 27

    Expert Comment

    man sh
     Backslash has no special meaning inside  a  pair  of  single quotes.
    but a single quote  can  not  be quoted inside a pair of single quotes.

    Will this command work as you like?
    awk '/^val=track/{print $4; next};{print $2}' file

    it's not you have asked for
    that is closer for your question:
    awk "/^val=track/{  print \"/bin/awk '{print \$4; exit 0}'\"; next};{print \$2}"
    Also if you want to get real $4 instead of just literal:
    awk "/^val=track/{  print \"/bin/awk '{print \" $4 \"; exit 0}'\"; next};{print \$2}"
    LVL 2

    Author Comment

    i have resolved the problem
    i put the awk command into file with this quote
    and i called awk -f awkscript file
    LVL 29

    Expert Comment


    Using two single quotes inside the pair of single quotes that delimit the awk statement also works.

    Accepted Solution

    PAQed with points refunded (50)

    Community Support Moderator

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
    The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now