For Programmers: Free Programming Magazines  


Home > Archive > AWK > February 2005 > [gawk] perform action on end of file?









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 [gawk] perform action on end of file?
Sandra

2005-01-31, 8:55 pm

Hi,

How do I print a certain line on the end of each file that has been read?
So not via the END command, because this will perform an action when all
files have been read..
Typically my awk script will read a number of input files, and it should
always print a certain line whenever the next file is read.
Something like 'if eof then print"xxxxxxxxx"'
How do I do this?

Sandra.
John DuBois

2005-01-31, 8:55 pm

In article <Xns95EFE34ED44A6antispamnospamcom@195.130.132.70>,
Sandra <antispam@nospam.com> wrote:
>Hi,
>
>How do I print a certain line on the end of each file that has been read?
>So not via the END command, because this will perform an action when all
>files have been read..
>Typically my awk script will read a number of input files, and it should
>always print a certain line whenever the next file is read.
>Something like 'if eof then print"xxxxxxxxx"'
>How do I do this?


Something like (assuming that the only arguments you give to your awk program
are filenames):

FNR == 1 && FILENAME != ARGV[1] { print "yourline" }
END { print "yourline" }
{ your further processing... }

This will print your line each time awk starts processing a new non-empty file
(except for the first one), as well as at the end.

John
--
John DuBois spcecdt@armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/
Kenny McCormack

2005-01-31, 8:55 pm

In article <Xns95EFE34ED44A6antispamnospamcom@195.130.132.70>,
Sandra <antispam@nospam.com> wrote:
>Hi,
>
>How do I print a certain line on the end of each file that has been read?
>So not via the END command, because this will perform an action when all
>files have been read..
>Typically my awk script will read a number of input files, and it should
>always print a certain line whenever the next file is read. Something
>like 'if eof then print"xxxxxxxxx"'
>How do I do this?


FILENAME != ofn { do_your_stuff();ofn=FILENAME }
....
END { do_your_stuff() }

And, for completeness, I'll add that when I do this sort of thing, the
first line of do_your_stuff() is: if (!ofn) return

Or use TAWK, and use the ENDFILE pattern (the above is the user-land
emulation of TAWK's ENDFILE {})

Sandra

2005-02-01, 3:56 pm

gazelle@yin.interaccess.com (Kenny McCormack) wrote in news:ctm9kf$ib4$1
@yin.interaccess.com:

> In article <Xns95EFE34ED44A6antispamnospamcom@195.130.132.70>,
> Sandra <antispam@nospam.com> wrote:
>
> FILENAME != ofn { do_your_stuff();ofn=FILENAME }
> ...
> END { do_your_stuff() }
>
> And, for completeness, I'll add that when I do this sort of thing, the
> first line of do_your_stuff() is: if (!ofn) return
>
> Or use TAWK, and use the ENDFILE pattern (the above is the user-land
> emulation of TAWK's ENDFILE {})
>


Hi,

Thanks for your help.
Could you please tell me if TAWK is very different from GAWK.. Can I still
use my GAWK code in TAWK? Where can i download TAWK (executable program)
for windowsXP?

Sandra.
Kenny McCormack

2005-02-05, 8:55 am

In article <Xns95F0CA263B287antispamnospamcom@195.130.132.70>,
Sandra <antispam@nospam.com> wrote:
....
>
>Hi,
>
>Thanks for your help.
>Could you please tell me if TAWK is very different from GAWK.. Can I still
>use my GAWK code in TAWK? Where can i download TAWK (executable program)
>for windowsXP?
>
>Sandra.


Well, as I posted elsewhere, the primary problem with TAWK is that you
can't get it (the company seems to have disappeared). But, I use it (TAWK)
all the time and couldn't live w/o it.

Having said that, I would say that TAWK is 98% downwards compatible with
GAWK, and has a lot of nifty useful features not found in GAWK. Offhand,
the only things I can thing of that GAWK has that TAWK doesn't are:

1) The switch statement
2) gensub()
3) IGNORECASE (said functionality is implemented differently [and,
IMHO, better] in TAWK)

Ed Morton

2005-02-05, 3:55 pm



Kenny McCormack wrote:

> In article <Xns95F0CA263B287antispamnospamcom@195.130.132.70>,
> Sandra <antispam@nospam.com> wrote:
> ...
>
>
>
> Well, as I posted elsewhere, the primary problem with TAWK is that you
> can't get it (the company seems to have disappeared).


So, when you post a suggestion that someone use tawk - what do you
expect them to do with that suggestion? Now poor Sandra is indubitably
off gnashing her teeth in frustration that there's this miraculous tool
that some special people get to use which would solve all her woes but
she's not allowed access to. I'm not picking on you I just honestly
wonder what the point is.

Ed.
Sandra

2005-02-06, 8:55 pm

< CUT>

>
> So, when you post a suggestion that someone use tawk - what do you
> expect them to do with that suggestion? Now poor Sandra is
> indubitably off gnashing her teeth in frustration that there's this
> miraculous tool that some special people get to use which would solve
> all her woes but she's not allowed access to. I'm not picking on you I
> just honestly wonder what the point is.
>
> Ed.
>


Guys,

I managed to do what I wanted with GAWK, so no problem!
Amazing what AWK can do if you know that it was written a long time ago..
and only a few 100Kb big..

Thanks for your help

Sandra
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com