[KLUG Members] Parsing a Text file
Andrew Eidson
aeidson at meglink.com
Wed Jul 20 13:16:55 EDT 2005
So the substr(0$, 1, 10); 1 is the starting position and 10 is the number of
characters in the field?? I will google it but I am in a bit of a time
crunch currently so any help would be greatly appreciated.
-----Original Message-----
From: members-bounces at kalamazoolinux.org
[mailto:members-bounces at kalamazoolinux.org] On Behalf Of Adam Tauno Williams
Sent: Wednesday, July 20, 2005 11:06 AM
To: The main KLUG mailing list.
Subject: Re: [KLUG Members] Parsing a Text file
> Hello all.. I was wondering what is the best way to Parse a fixed length
> text file in linux.. I have a file that is 900 Characters long and needs
to
> be broken out into a comma or tab delimited file so I can then import it
> into another database application. The application does not handle fixed
> length files with no delimiters... For those of you in schools you may
have
> something since this is a State SRSD file that I need to Parse.. but just
> wondering what I should use.
AWK - installed on every single UNIX box ever - available for Win32 -
and has ZERO dependencies.
BEGIN {}
{
$field1 = substr($0, 1, 10);
$field2 = substr($0, 15, 5);
printf("%s|%8.2f\n", $field1, $field2);
}
END {}
- then -
awk -f {myawkfile} < {myinputfile}
Fast and simple.
_______________________________________________
Members mailing list
Members at kalamazoolinux.org
More information about the Members
mailing list