By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 950 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

How to compare strings using awk?

P: 34
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

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

Thanks & Regards
Sathish Kumar
Oct 17 '10 #1
Share this Question
Share on Google+
1 Reply


ashitpro
Expert 100+
P: 542
Expand|Select|Wrap|Line Numbers
  1. 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.
Oct 18 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.