Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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 withY;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

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

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

![]() |
![]() |
![]() |

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