Find the answer to your Linux question:
Results 1 to 5 of 5
I keep getting a syntax error when I try to run this script, I have tried moving things around but I keep getting the same result, what am I doing ...
  1. #1
    Just Joined!
    Join Date
    May 2008
    Posts
    2

    [SOLVED] running awk

    I keep getting a syntax error when I try to run this script, I have tried moving things around but I keep getting the same result, what am I doing wrong?

    #!/bin/awk -f
    awk '{print "Name", $1, $2
    print "Phone Number", $3
    print " "}' phone.list

  2. #2
    Linux User dxqcanada's Avatar
    Join Date
    Sep 2006
    Location
    Canada
    Posts
    259
    You only need to use the "print" statement once, at the beginning.
    Code:
    #!/bin/awk -f
    awk '{print "Name", $1, $2, "Phone Number", $3," "}' phone.list



    Men occasionally stumble over the truth,
    but most of them pick themselves up
    and hurry off as if nothing had happened.

    Winston Churchill


    ... then the Unix-Gods created "man" ...

  3. #3
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    I think alink wants to run awk in a script and have 3 lines of output for every line in the phone.list file. The script should look like as:

    Code:
    #!/bin/bash
    awk '{print "Name", $1, $2 
    print "Phone Number", $3
    print " "}' phone.list
    To do it with a single print command it would look like:

    Code:
    #!/bin/bash
    awk '{print "Name", $1, $2, "\nPhone Number", $3, "\n"}' phone.list

  4. #4
    Just Joined!
    Join Date
    May 2008
    Posts
    2
    Thanks I will try it right now

  5. #5
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    Quote Originally Posted by alink View Post
    I keep getting a syntax error when I try to run this script, I have tried moving things around but I keep getting the same result, what am I doing wrong?

    #!/bin/awk -f
    awk '{print "Name", $1, $2
    print "Phone Number", $3
    print " "}' phone.list
    To answer the original question, it's your shebang line that's broken - use /bin/bash as vsemaska suggests. Or do the lot in a shell:
    [code]
    #!/bin/bash
    while read name1 name2 phone
    do
    printf "%s %s\nPhone Number %s\n\n" $name1 $name2 $phone
    done <phone.list

Posting Permissions

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