[Haskell-cafe] Sneaking haskell in the workplace -- cleaning csv
files
Jason Dagit
dagit at codersbase.com
Fri Jun 15 18:37:10 EDT 2007
On 6/15/07, Jim Burton <jim at sdf-eu.org> wrote:
> Sebastian Sylvan wrote:
> > On 15/06/07, Jim Burton <jim at sdf-eu.org> wrote:
> [snip]
> > Hi,
> Hi Sebastian,
> > I haven't compiled this, but you get the general idea:
> >
> > import qualified Data.ByteString.Lazy.Char8 as B
> > -- takes a bytestring representing the file, concats the lines
> > -- then splits it up into "real" lines using the delimiter
> > clean :: Char -> B.ByteString -> [B.ByteString]
> > clean' d = B.split d . B.concat . B.lines
>
> I think that would only work if there was one column per line...I didn't
> make it clear that as well as being comma separated, the delimiter is
> around each column, of which there are several on a line so if the
> delimiter is ~ a file might look like:
>
> ~sdlkfj~, ~dsdkjf~ #eo row1
> ~sdf
> dfkj~, ~dfsd~ #eo row 2
I love to see people using Haskell, especially professionally, but I
have to wonder if the real tool for this job is sed? :-)
Jason
More information about the Haskell-Cafe
mailing list