Find the answer to your Linux question:
Results 1 to 7 of 7
i tried this one: BEGIN { print " Hello " } { find -name taufiq.txt } END { print "Finished " } is there anything wrong with the code or ...
  1. #1
    Just Joined!
    Join Date
    Jul 2007
    Posts
    34

    can AWK accept Shell cript?

    i tried this one:

    BEGIN { print " Hello " }

    {
    find -name taufiq.txt

    }


    END { print "Finished " }


    is there anything wrong with the code or the AWK does not accept Shell command in its script. the error produce is:

    awk: MyName.awk:4: find -name taufiq.txt
    awk: MyName.awk:4:..............................^ syntax error

  2. #2
    Just Joined!
    Join Date
    Oct 2007
    Posts
    37
    I don't recognize this. What are you trying to do exactly?

  3. #3
    Just Joined!
    Join Date
    Jul 2007
    Posts
    34
    i just want to know, does AWK accept SHELL command if we embed the SHELL command in AWK script. Will AWK execute?

    because what i want to try latter is create 20 user account using the "adduser" where the user name will be from a text document containing the name of the user account.

  4. #4
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    Quote Originally Posted by cruzerMicro View Post
    i just want to know, does AWK accept SHELL command if we embed the SHELL command in AWK script. Will AWK execute?
    yes but not the way you did it.
    to execute external command from within awk, most common method is using the system() function

    Code:
    awk ' {
           cmd = "construct your command here"
           system(cmd)
    '

  5. #5
    Just Joined!
    Join Date
    Oct 2007
    Posts
    37
    You could also do it a simpler way by just running:

    for user in `cat textfile.txt`; do adduser $user; done

    or if needed...

    for user in `cat textfile.txt | awk '{print $1}'`; do adduser $user; done

    Of course replace textfile.txt with your file and the $1 with the column you need.

  6. #6
    Just Joined!
    Join Date
    Jul 2007
    Posts
    34
    Quote Originally Posted by papetova View Post
    You could also do it a simpler way by just running:

    for user in `cat textfile.txt | awk '{print $1}'`; do adduser $user; done

    Of course replace textfile.txt with your file and the $1 with the column you need.
    hay thanks. but whats the awk '{print $1}' for?

  7. #7
    Just Joined!
    Join Date
    Oct 2007
    Posts
    37
    It jst grabs the first column delimited by space, so if you had "john ", it would only grab "john".

    Probably not needed, but useful for more than one column.

    $1 - column 1
    $2 - column 2

    and so on.

Posting Permissions

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