From kevin1a at varlog.net Mon Apr 26 22:16:04 2004 From: kevin1a at varlog.net (Kevin Brouelette) Date: Mon, 26 Apr 2004 22:16:04 -0700 Subject: [OCLUG-devel] Learning awk Message-ID: <1083042964.1490.20.camel@athlon.kblan.com> Hello, I'm spending my weeknights this week brushing up on bash shell. The book I'm working with is Addison-Wesley's 'Linux & Unix shell Programing' by David Tansley. Chapter 9 is about 'awk'. After reading the chapter, I thought I would try to use awk to grab the users which their UID from /etc/passwd is greater than 999. [Slackware UIDs start at 1000] So I try this: awk -F: '{if($2 > 999) print$0"\t"$2}' /etc/passwd hoping to print the name, a 'tab', and the UID. It echo's the whole /etc/passwd file and no errors. Am I close or am I off base with trying to do this with awk? TIA Kevin B From kevin1a at varlog.net Mon Apr 26 22:32:38 2004 From: kevin1a at varlog.net (Kevin Brouelette) Date: Mon, 26 Apr 2004 22:32:38 -0700 Subject: [OCLUG-devel] Learning awk In-Reply-To: <1083042964.1490.20.camel@athlon.kblan.com> References: <1083042964.1490.20.camel@athlon.kblan.com> Message-ID: <1083043958.1490.23.camel@athlon.kblan.com> On Mon, 2004-04-26 at 22:16, Kevin Brouelette wrote: > Hello, > > I'm spending my weeknights this week brushing up on bash shell. > The book I'm working with is Addison-Wesley's 'Linux & Unix shell > Programing' by David Tansley. > > Chapter 9 is about 'awk'. > After reading the chapter, > I thought I would try to use awk to grab the users > which their UID from /etc/passwd is greater than 999. > [Slackware UIDs start at 1000] > > So I try this: > awk -F: '{if($2 > 999) print$0"\t"$2}' /etc/passwd > > hoping to print the name, a 'tab', and the UID. > > It echo's the whole /etc/passwd file and no errors. > Am I close or am I off base with trying to do this with awk? > > TIA > > Kevin B The obvious strikes. $0 prints the whole line. awk -F: '{if($3 > 999) print$1"\t"$3}' /etc/passwd Works. I have a lot of reading to do. :) Kevin From panfisher at earthlink.net Tue Apr 27 10:33:31 2004 From: panfisher at earthlink.net (Tony Dycks) Date: Tue, 27 Apr 2004 10:33:31 -0700 Subject: [OCLUG-devel] Learning awk/Another Decent Book References: <1083042964.1490.20.camel@athlon.kblan.com> <1083043958.1490.23.camel@athlon.kblan.com> Message-ID: <000d01c42c7d$c2b1c1a0$a536fea9@percival> ----- Original Message ----- From: "Kevin Brouelette" To: Sent: Monday, April 26, 2004 10:32 PM Subject: Re: [OCLUG-devel] Learning awk > On Mon, 2004-04-26 at 22:16, Kevin Brouelette wrote: > > Hello, > > > > I'm spending my weeknights this week brushing up on bash shell. > > The book I'm working with is Addison-Wesley's 'Linux & Unix shell > > Programing' by David Tansley. > > > > Chapter 9 is about 'awk'. > > After reading the chapter, > > I thought I would try to use awk to grab the users > > which their UID from /etc/passwd is greater than 999. > > [Slackware UIDs start at 1000] > > > > So I try this: > > awk -F: '{if($2 > 999) print$0"\t"$2}' /etc/passwd > > > > hoping to print the name, a 'tab', and the UID. > > > > It echo's the whole /etc/passwd file and no errors. > > Am I close or am I off base with trying to do this with awk? > > > > TIA > > > > Kevin B > > > The obvious strikes. $0 prints the whole line. > > awk -F: '{if($3 > 999) print$1"\t"$3}' /etc/passwd > > Works. I have a lot of reading to do. :) > > Kevin > > > Another good reference on Awk is the O'Reilly "Sed & Awk" publication by Dale Dougherty & Arnold Robbines. Cover price; $29.95 for the 2nd Edition (might be a newer version out) Awk is a great shorthand shell language for working with consistent file structures. _______________________________________________ > OCLUG-devel mailing list -- OCLUG-devel at oclug.org > http://www.oclug.org/mailman/listinfo/oclug-devel