Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: awk tutoria...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 11 Topic 2222 of 2241
Post > Topic >>

Re: awk tutorial confusion

by Ed Morton <morton@[EMAIL PROTECTED] > Apr 14, 2008 at 06:00 AM

On 4/14/2008 3:53 AM, r wrote:
> Readers,
> 
> I am reading a tutorial, to learn how to use awk (http://
> www.grymoire.com/Unix/Awk.html).
> 
> I've copied the following text and saved in the filenames shown:
> 
> fileowner:
> 
> #!/bin/sh
> awk'
> 	BEGIN {print"file\towner"}
> 		{print $8,"\t",$3}
> 	END {print "-done-"}
> '
> 
> fileowner2:
> 
> #!/bin/sh
> awk '
> BEGIN { print "File\tOwner" }
> { print $8, "\t",
> $3}
> END { print "done"}
> '
> 
> fileowner3:
> 
> #!/bin/sh
> column=$1
> awk '{print $column}'
> 
> 
> Below is my various command terminal errors:
> 
> $ awk -f fileowner.awk
> awk: fileowner.awk:2: awk'
> awk: fileowner.awk:2:    ^ invalid char ''' in expression
> $ awk -f fileowner2
> awk: fileowner2:2: awk '
> awk: fileowner2:2:     ^ invalid char ''' in expression
> $ ls -l|Column 3
> bash: Column: command not found

What's "Column"?

> $ ls -l|fileowner3
> bash: fileowner3: command not found
> 
> Regarding the fileowner file, I obtained the same error both when the
> filename has no suffix and when the suffix is .awk. Subsequently I did
> not use .awk farther. What am I doing wrong?
> 
> Yours,
> 
> gnu mandriva 2008
> gnome 24

It's got nothing to do with the file suffix. Change your files to this:

fileowner.awk:

BEGIN {print"file\towner"}
{print $9 "\t" $3}
END {print "-done-"}

fileowner2:

BEGIN { print "File\tOwner" }
{ print $9 "\t" $3}
END { print "done"}

fileowner3:

#!/bin/sh
awk -v column="$1" '{print column}'

Then make fileowner3 executable and do this in the directory where you
created
the files:

$ ls -l | awk -f fileowner.awk
$ ls -l | awk -f fileowner2
$ ls -l | ./fileowner3 3

Regards,

	Ed.




 11 Posts in Topic:
awk tutorial confusion
r <inpost@[EMAIL PROTE  2008-04-14 01:53:41 
Re: awk tutorial confusion
Ed Morton <morton@[EMA  2008-04-14 06:00:16 
Re: awk tutorial confusion
Ed Morton <morton@[EMA  2008-04-14 06:21:55 
Re: awk tutorial confusion
Bruce Barnett <spamhat  2008-04-16 15:13:08 
Re: awk tutorial confusion
Ed Morton <morton@[EMA  2008-04-16 17:12:31 
Re: awk tutorial confusion
Bruce Barnett <spamhat  2008-04-17 20:11:28 
Re: awk tutorial confusion
Ed Morton <morton@[EMA  2008-04-17 23:48:23 
OT: Re: awk tutorial confusion
Ed Morton <morton@[EMA  2008-04-17 00:22:15 
Re: awk tutorial confusion
Bruce Barnett <spamhat  2008-04-16 14:28:50 
Re: awk tutorial confusion
r <inpost@[EMAIL PROTE  2008-04-16 14:42:52 
Re: awk tutorial confusion
Bruce Barnett <spamhat  2008-04-17 20:02:09 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 4:30:54 CDT 2008.