|
Home > Archive > Unix administration > September 2007 > Shebang line for an awk script?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Shebang line for an awk script?
|
|
| Doug Freyburger 2007-09-12, 7:20 pm |
| Folks,
What do you put on the shebang line for an awk script?
I've been getting:
# ./passwd.process.awk /etc/passwd
awk: syntax error near line 1
awk: bailing out near line 1
On Solaris. On HPUX it complains about the dot in the
name of the script. Here's what I'm trying to do:
#! /usr/bin/awk -F: -f -
BEGIN {
print( "Username User ID Human name" );
}
{
if ( length( $5 ) > 0 )
if ( length( $1 ) < 7 )
print( $1 , " " , $3 , " " , $5 )
else
print( $1 , " " , $3 , " " , $5 );
}
END {
print( "" );
}
It works to run it by hand:
/usr/bin/awk -F: -f ./process.passwd.awk /etc/passwd | more
But that's no fun at all. Misses what the shebang is for.
I don't have a problem with "#! /usr/bin/perl" or "#! /bin/ksh" for
my scripts in those languages and awk is just a nother
scripting language.
I tried it with "-f" but no dash, and without the "-f -" at all.
No change in the output. File is "chmod 755 process.passwd.awk".
| |
| Barry Margolin 2007-09-13, 1:19 am |
| In article <1189630829.029638.166560@57g2000hsv.googlegroups.com>,
Doug Freyburger <dfreybur@yahoo.com> wrote:
> Folks,
>
> What do you put on the shebang line for an awk script?
> I've been getting:
>
> # ./passwd.process.awk /etc/passwd
> awk: syntax error near line 1
> awk: bailing out near line 1
>
> On Solaris. On HPUX it complains about the dot in the
> name of the script. Here's what I'm trying to do:
>
> #! /usr/bin/awk -F: -f -
> BEGIN {
> print( "Username User ID Human name" );
> }
> {
> if ( length( $5 ) > 0 )
> if ( length( $1 ) < 7 )
> print( $1 , " " , $3 , " " , $5 )
> else
> print( $1 , " " , $3 , " " , $5 );
> }
> END {
> print( "" );
> }
>
> It works to run it by hand:
>
> /usr/bin/awk -F: -f ./process.passwd.awk /etc/passwd | more
>
> But that's no fun at all. Misses what the shebang is for.
> I don't have a problem with "#! /usr/bin/perl" or "#! /bin/ksh" for
> my scripts in those languages and awk is just a nother
> scripting language.
>
> I tried it with "-f" but no dash, and without the "-f -" at all.
> No change in the output. File is "chmod 755 process.passwd.awk".
It works for me on OS X with
#! /usr/bin/awk -F: -f
However, I believe many flavors of Unix only allow one argument on the
shebang line, and ignore any additional arguments, so you can't have
both -f and -F:.
Since -F: is equivalent to assigning to the FS variable, you can get the
same effect by putting
FS = ":";
in your BEGIN block.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
| |
| Doug Freyburger 2007-09-13, 7:31 pm |
| Barry Margolin <bar...@alum.mit.edu> wrote:
> Doug Freyburger <dfrey...@yahoo.com> wrote:
>
>
>
>
....[vbcol=seagreen]
> It works for me on OS X with
>
> #! /usr/bin/awk -F: -f
>
> However, I believe many flavors of Unix only allow one argument on the
> shebang line, and ignore any additional arguments, so you can't have
> both -f and -F:.
>
> Since -F: is equivalent to assigning to the FS variable, you can get the
> same effect by putting
>
> FS = ":";
>
> in your BEGIN block.
Thanks Barry! Virtual beer. Or I ever get to another LISA
conference,
physical beer.
|
|
|
|
|