On Mar 2, 12:34 pm, Luuk <L...@[EMAIL PROTECTED]
> wrote:
> Radu schreef:
>
>
>
> > Hi everybody,
>
> > Input file:
>
> > ID |First name |Last name |Address
|
> > Phone |
> >
--------------------------------------------------------------------------------------------------------------
> > <--10-->|<----15----->|<----20----->|
> > <--------30------------------------>|<---14------------->|
> >
--------------------------------------------------------------------------------------------------------------
> > 4568 |Michael |Moore |350 Kensington Rd. |
> > (514) 567-1234 |
> > 63542 |James |Joyce |220 London Blv. |
> > (450) 234-1456 |
>
> > I need to trim all blanks of each fixed-length field (notice there are
> > blanks within each field that may be seen as field separators by awk
> > if not treated correctly). The output file I'm looking for (a CSV
> > file) would be like:
>
> > 4568,Michael,Moore, 350 Kensington Rd.,(514) 567-1234
> > 63542,James,Joyce,220 London Blv.,(450) 234-1456
>
> > Thanks,
>
> > Radu
>
> awk '{ gsub(/\|/,","); print ; gsub(" \+"," "); gsub(" ,",","); print'
> inputfile
>
> --
> Luuk
Thanks Luuk,
All seems fine, only I did a "small" mistake.
The fields are not separated by "|" but by blanks.
So the record will be something like
4568 Michael Moore 350 Kensington Rd. (514)
567-1234
All I have is the fixed-length of each field. I guess I need to trim
all leading and trailing spaces (but not the inside ones, even if they
repeat on several positions) and separate the fields with ",".
Thanks again,
Radu


|