Date: Thu, 20 Jan 2000 10:59:45 +0530 From: "SIVARAM N" <sivaramn@wipsys.ge.com> To: <freebsd-questions@freebsd.org> Message-ID: <00e501bf6307$5cd13a80$8b2fa8c0@wipsys.ge.com>
next in thread | raw e-mail | index | archive | help
Hi,
I hope this is the right list to ask...
I have 2 questions actually.
1. I have a comma separated records in a file where most fields have leading
whitespaces. Setting FS="," & reading the file preserves the leading whitespaces.
how do I remove them? I have gawk installed & there's this match() operator where
it sets the RSTART & RLENGTH parameter. Now , I'm not getting the code right
which looks for spaces at the beginning of the field . Why doesn't this work
BEGIN {spc="^[ ][ ]*"}
...
if($2 ~spc ){ pos=match($2,spc)
....
2. How can you find out whether the end of file has been reached for a specific file
given multiple files?
I have 2 files , the first needs to be read into an associative array in BEGIN before
I work with the second file in the body of the program . How do I check for end of file
in BEGIN?
One suggestion I got was to mark the last line of the first file with a marker like
NEXTFILE
BEGIN { FS=","; state="preload"; I=1}
{
if($0~/^NEXTFILE/) { state="loaded2"; next
}
if(state == "preload")
...<load array>
else {
... <lookup up array for values got from 2nd file>
Supposing I dont want to touch the files??
Regards,
Sivaram
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?00e501bf6307$5cd13a80$8b2fa8c0>
