Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: Trim right ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 12 Topic 2176 of 2236
Post > Topic >>

Re: Trim right blanks in each fixed-length field

by Radu <raducocos@[EMAIL PROTECTED] > Mar 2, 2008 at 10:38 AM

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




 12 Posts in Topic:
Trim right blanks in each fixed-length field
Radu <raducocos@[EMAIL  2008-03-02 08:59:55 
Re: Trim right blanks in each fixed-length field
Luuk <Luuk@[EMAIL PROT  2008-03-02 18:26:32 
Re: Trim right blanks in each fixed-length field
Luuk <Luuk@[EMAIL PROT  2008-03-02 18:34:08 
Re: Trim right blanks in each fixed-length field
Radu <raducocos@[EMAIL  2008-03-02 10:38:52 
Re: Trim right blanks in each fixed-length field
Luuk <Luuk@[EMAIL PROT  2008-03-02 20:24:57 
Re: Trim right blanks in each fixed-length field
Radu <raducocos@[EMAIL  2008-03-02 11:57:11 
Re: Trim right blanks in each fixed-length field
Ed Morton <morton@[EMA  2008-03-02 20:37:03 
Re: Trim right blanks in each fixed-length field
Luuk <Luuk@[EMAIL PROT  2008-03-03 10:37:36 
Re: Trim right blanks in each fixed-length field
Radu <raducocos@[EMAIL  2008-03-03 08:25:19 
Re: Trim right blanks in each fixed-length field
Ed Morton <morton@[EMA  2008-03-03 11:52:48 
Re: Trim right blanks in each fixed-length field
Luuk <Luuk@[EMAIL PROT  2008-03-03 19:24:52 
Re: Trim right blanks in each fixed-length field
Ed Morton <morton@[EMA  2008-03-03 13:18:35 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri May 16 10:56:03 CDT 2008.