[KLUG Members] Parsing a Text file
Adam Tauno Williams
adam at morrison-ind.com
Wed Jul 20 11:05:37 EDT 2005
> 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.
More information about the Members
mailing list