Operating System - Linux
1753767 Members
5577 Online
108799 Solutions
New Discussion юеВ

Re: awk vs. perl ... print $1?

 
SOLVED
Go to solution
A. Daniel King_1
Super Advisor

Re: awk vs. perl ... print $1?

Steve,

Could you clarify the meaning of the //?

Thanks.
Command-Line Junkie
Caesar_3
Esteemed Contributor

Re: awk vs. perl ... print $1?

Hello!

perl -aF: -nel 'print $F[0]'/etc/passwd
Should work.

Caesar
Steve Post
Trusted Contributor

Re: awk vs. perl ... print $1?

I thought this message had already run its course. Sorry. About that.

On the "//" in the Awk command.
The // means "for every line."

You didn't have // in your awk script. I don't know what it was doing.

Normally I use awk this way.

cat file | awk ' { action to do}'

You gave awk an action to do, but did not select any lines?

other selections.
if field 2 is not billy, print the line.
awk '$2 !~ /billy/ { print $0 }'

if the line begins with hoohay, print field 3.
awk '/^hoohay/ { print $3 }'

print something at the start and end.
awk 'BEGIN { print "this is the start.\n" }
// { printf("here is a line %s\n",$0) }
END { print "this is the end." }'

steve.
Tim D Fulford
Honored Contributor

Re: awk vs. perl ... print $1?

Hi

// is implied so...
awk '{print $1}' file
is the same as
awk '//{print $1}'

I never use // & my awk works fine!!!!

Tim
-
Tim D Fulford
Honored Contributor

Re: awk vs. perl ... print $1?

Hi

// is implied so...
awk '{print $1}' file
is the same as
awk '//{print $1}' file

I never use // & my awk works fine!!!!

Tim
-
Steve Post
Trusted Contributor

Re: awk vs. perl ... print $1?

ok Tim. I bet you're right. But I'm not the author. I can't see what version of awk he's using.
Maybe // does not have to be there.
I just put it in out of habit. In any case, you see it means "grab all lines."
steve
Brian Burroughs
New Member

Re: awk vs. perl ... print $1?

Old postings I know but...
Try this! Much more readable.

cat /etc/passwd | perl -anF: -e 'print $F[0],"\n"' -

Substitute the 0 for whichever column you want.
Stuart Browne
Honored Contributor

Re: awk vs. perl ... print $1?

Ugh. Actually, that is basically what procura and Mike's posts said.

During one of the forum upgrades however, all ['s got translated into their html [ values, and ]'s into ].
One long-haired git at your service...
Brian Burroughs
New Member

Re: awk vs. perl ... print $1?

LOL

Here's me thinking I was being clever.
A. Daniel King_1
Super Advisor

Re: awk vs. perl ... print $1?

Not quite as elegant, but probably more extensible. Thanks, all.
Command-Line Junkie