Computing.Net > Forums > Unix > unix text file parser

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

unix text file parser

Reply to Message Icon

Name: Irene
Date: August 7, 2003 at 01:29:00 Pacific
OS: Windows 2000
CPU/Ram: P 4/256 MB
Comment:

Hi all,
I'm working on Exceed (unix machine) from Windows.
With a grep command on a file I build a new text file
in UNIX in wich every line is of type:

X:Y;Z;K;A,B\n


I have to fill an Oracle db table (by SQLLoader*) only with fields
Y - Z - K - A


So before submitting the text file to SQLLoader I must
'clean' it by replacing each line with

Y;Z;K;A\n

How can I build a text file parser in UNIX ?
Which instrument should I use and which extension should have
the command parser ?


Thank You very much,
Irene



Sponsored Link
Ads by Google

Response Number 1
Name: Dlonra
Date: August 7, 2003 at 14:27:12 Pacific
Reply:

assuming there are no other ":" or "," on a line, pipe your grep through:
sed -e 's/^.*://' -e 's/,.*//'


0

Response Number 2
Name: James Boothe
Date: August 7, 2003 at 15:27:22 Pacific
Reply:

That sed command will eliminate the extraneous data from your first and fourth fields, but as Dlonra points out, if fields 2 or 3 contain any colons or commas, the sed command chops too much.

The awk code below edits only those two fields, leaving remainder of line along.  It prints each line in csv format in case any of the fields have embedded commas.

awk -F\; '\
{sub(".*:","",$1)
 sub(",.*","",$4)
 printf "\"%s\",\"%s\",\"%s\",\"%s\"\n",$1,$2,$3,$4
}' filein > fileout


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: unix text file parser

Printing Unix text properly (URGENT) www.computing.net/answers/unix/printing-unix-text-properly-urgent/3085.html

Transfering text files to dos www.computing.net/answers/unix/transfering-text-files-to-dos/2269.html

How to convert text file to html www.computing.net/answers/unix/how-to-convert-text-file-to-html/4709.html