Thread: Awk script

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2006
    Posts
    319
    Rep Power
    9

    Awk script


    Hi,

    Why doesn't the following script print the entries of 'root' user in /etc/password ?

    Code:
     awk -F : 'BEGIN {if ($1 ~ /root/){print $0}}' /etc/passwd
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,180
    Rep Power
    9398
    Because you told it to run that condition at the BEGINning, not on each line.
    Code:
    awk -F : '{if ($1 == "root"){print $0}}' /etc/passwd

IMN logo majestic logo threadwatch logo seochat tools logo