How to compare strings using awk?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sathishc58
    New Member
    • Sep 2007
    • 34

    How to compare strings using awk?

    Hi All,

    I have the following text file and I want to display only the lines where "Vacancy" field (or column) is set to "YES".

    $ cat movielist
    [Showtimes],[Movie Title],[Vacancy]
    1300 2Oct,X-files,Yes
    1600 2Oct,Xmen,No
    1700 2Oct,Spiderman, Yes

    Code:
          1 show_file()
          2 {
          3     echo "Show file is called";
          4     awk -F',' '
          5               {
          6                   [B]if ($3 ~ (/^YES/))[/B]
          7                   {
          8                       {print $2, $1, $3};
          9                   }
         10
         11               }' movielist
         12 }
         13
    I tried but I was not successful. What change should I do at line no 6?

    Thanks & Regards
    Sathish Kumar
  • ashitpro
    Recognized Expert Contributor
    • Aug 2007
    • 542

    #2
    Code:
    awk -F',' '$3 ~ /Yes/ {print $3}' a.txt
    I haven't check your script; but I thing 'YES' should be 'Yes'. Check if that work otherwise see if mine works for you.

    Comment

    Working...