Thread: Awk script

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

    Join Date
    Sep 2006
    Posts
    319
    Rep Power
    8

    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. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,754
    Rep Power
    9397
    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