Find the answer to your Linux question:
Results 1 to 2 of 2
Hi guys, basically i need to check if the 2nd column of /etc/passwd contains "x". If it contain "x", print "exception:no" if it doesn't ( blank), print "exception yes" I ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2012
    Posts
    6

    Exclamation Need Help on a bash script


    Hi guys, basically i need to check if the 2nd column of /etc/passwd contains "x". If it contain "x", print "exception:no" if it doesn't ( blank), print "exception yes"

    I need to check the whole of /etc/passwd.

    im trying to use if else or for loop. grep and awk is also accepted if i can get it to work.



    I tried doing awk but while it does work, it prints out "no" for every user that does have an "x" in 2nd column of their line, and "yes" for every user that does not have "x" in 2nd column of their line.

    I just need one yes or no.

    Any help?
    Last edited by marcus5; 11-08-2012 at 03:41 PM.

  2. #2
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    237
    hi,

    use a "switch" variable.
    if $2 is not x, then switch it on
    at the end of the file, if switch is on print yes, or no.

    NB: your emergency is not ours.
    we don't care, and it's not polite to tell your job is urgent!

Posting Permissions

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