Re: Want to replace SPACE delimited data file with commas
- From: "CarltonG" <carlton_gregory@xxxxxxxxx>
- Date: 6 Dec 2006 12:51:21 -0800
There will always be three fields after the description EXCEPT I am
looking for the group of records that has only TWO after the
description.
I dont care about the other records
It will be records that start with 052. They will only have two fields
after the description.
And they will be the only ones delimited by spaces. The other records
have commas.
The fields for 052 records are separated by spaces not tabs
The fields for all records are length determinable by position. Meaning
if I took out the commas I still would know when they start and end.
1-3 zone
5-15 code
etc etc
I will have to preview my post next time so it wont wrap. Every line
starts with a three digit id always so 003 is the start of a new line.
This is a dump from an Oracle DB so I would have to find the pl/sql
code for tab ( chr(10) I think ) as I am using the PL/SQL file I/O API
to write this file
Thanks for your help this gets me started
Stephane CHAZELAS wrote:
2006-12-6, 11:38(-08), CarltonG:
Hello,[...]
I have a datafile that looks like this:
003 68441896104 8 CHEERLEADER BEAR 0510 00001599 00000000
003 68441896108 8 VARSITY BEAR 0510 00001599
00000000
003 68441896106 SAILOR BEAR WHITES 0510 00001599
00000000
003 336037204651 SENSI WMN 3.4 SPR 0592 00006000
00000000
003 76968229001 111404 0597
00001299 00000000
I want to be able to define a specific id ( in this case 003 ) and for
all those records
replace the spaces that seperate each value with a comma.
Problem is the third value ( description ) has spaces in it.
I know awk can get each file but I honestly dont know the possible
number of spaces that could be in the description field.
Can anyone point me in the right direction? I think this is pretty
complex but I could be wrong.
If the number of fields before and after the 3rd field is
always the same, I'd go for sed:
b='[[:blank:]]\{1,\}' # blanks
f='\([^[:blank:]]\{1,\}\)' # single word field
sed "s/^$f$b$f$b\(.*[^[:blank:]]\)$b$f$b$f$b$f$/\1,\2,\3,\4,\5,\6/"
--
Stéphane
.
- References:
- Want to replace SPACE delimited data file with commas
- From: CarltonG
- Re: Want to replace SPACE delimited data file with commas
- From: Stephane CHAZELAS
- Want to replace SPACE delimited data file with commas
- Prev by Date: Re: How do I print only the first grep match?
- Next by Date: awk question - range selection
- Previous by thread: Re: Want to replace SPACE delimited data file with commas
- Next by thread: Re: Want to replace SPACE delimited data file with commas
- Index(es):
Relevant Pages
|