From: #! /shell/nerd on
Is there anyway to quit awk script after acting on just first line?
From: Seebs on
On 2010-04-01, #! /shell/nerd <vikasera(a)gmail.com> wrote:
> Is there anyway to quit awk script after acting on just first line?

Yes, but if you want to, the chances are about 99:1 that you are doing
something wrong. There is no reason to exit on the first line of input,
or rather, if there were, it would be a sign that the input shouldn't
be going to awk to begin with.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: Bill Marcum on
On 2010-04-01, #! /shell/nerd <vikasera(a)gmail.com> wrote:
> Is there anyway to quit awk script after acting on just first line?

NR==1 {do_something; exit}
or
head -n 1 | awk
From: Chris F.A. Johnson on
On 2010-04-01, #! /shell/nerd wrote:
> Is there anyway to quit awk script after acting on just first line?

awk 'NR == 1 { whatever; exit }' "$file"

If you only need to process one line, you usually don't need awk
(or head or any external command):

IFS= read -r line < "$file"

--
Chris F.A. Johnson, author <http://shell.cfajohnson.com/>
===================================================================
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
===== My code in this post, if any, assumes the POSIX locale =====
===== and is released under the GNU General Public Licence =====