Re: Removing rogue ciarraige returns in data file
From: rakesh sharma (sharma__r_at_hotmail.com)
Date: 08/21/03
- Next message: rakesh sharma: "Re: how to handle record size longer than 255 characters"
- Previous message: Alan Connor: "Re: Sed command, Insert text in front of existing line"
- In reply to: Jonathan: "Removing rogue ciarraige returns in data file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 21 Aug 2003 14:31:25 -0700
"Jonathan" <jonathan@bakerbates.SPAMGONE.com> wrote in message news:<L3J0b.9471$z7.1155128@wards.force9.net>...
> Hi,
>
> I'm having a hard time with a CSV file that has carriage returns in a postal
> address field, making the number of columns vary. Has anyone got any
> pointers on how I can mend this?
>
> For example, the data looks like this right now:
>
> field1,field2,field3,field4,field5
> field1,field2,field3,field4,field5
> field1,field2,field3
> ,field4,field5
> field1,field2,field3,field4,field5
>
> (Note the CR at the end of field3 in the column 3)
>
> I'd like to fix it so it looks like this:
>
> field1,field2,field3,field4,field5
> field1,field2,field3,field4,field5
> field1,field2,field3,field4,field5
> field1,field2,field3,field4,field5
>
sed -e '
s/[^,]*,/&\
/4
tok
N
:ok
s/\n//
' datafile
note: failures will occur when
a) any line ends with a ',' ,e.g.,
field1,field2,field3,
field4,field5
b) fields spill over more than 2 lines, e.g.,
field1,field2
,field3,field4
,field5
c) there are empty lines or lines with no commas.
- Next message: rakesh sharma: "Re: how to handle record size longer than 255 characters"
- Previous message: Alan Connor: "Re: Sed command, Insert text in front of existing line"
- In reply to: Jonathan: "Removing rogue ciarraige returns in data file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|