[ale] sed and massively editing files.

Hunter Eidson hunter at gpc.edu
Mon Nov 13 10:02:16 EST 2006


I'm sure there's a prettier way to do it, but this seems to work...

Create a file called fixup.sed which contains these 3 lines:

:START
s/{\(.*\)'\(.*\)}/{\1\"\2}/g
t START

Now, assuming your data file is datafile.sql, you should be able to run:

sed -f fixup.sed < datafile.sql > new_datafile.sql

Hope this helps...

    --Hunter

Michael B. Trausch wrote:
> I am pretty sure that sed is the tool for what I want to do, but I
> can't be sure.  I have it doing everything else that I need.  The
> lines that I have are from a ZIP code database in SQL, but I need to
> make some formatting fixups to the entire thing (42,320 lines).
>
> Each line is like this:
>
> INSERT INTO zip_summary (zip, city, state, county, area_codes,
> city_type, latitude, longitude, time_zone, county_fips, observes_dst)
> VALUES ('10452', 'Bronx', 'NY', 'Bronx', '{'347', '646', '718'}', 'P',
> 40.838324, -73.921892, '-0500', '005', TRUE);
>
> Now, what I need to do is convert the ' characters to be " characters,
> but only inside of {...} (where the area code list is).  I can't seem
> to figure out how to do that, though, because if I use a s/.../...
> expression, it would replace the entire thing, which isn't what I
> want.  Is there a regex that will say "Match an apostrophe if between
> squiggly brackets" so that I can replace each occurrence with a
> quotation mark?
>
>     -- Mike
>
> --
> Michael B. Trausch 	
> fd0man at gmail.com <mailto:fd0man at gmail.com>
> Phone: (404) 592-5746 	
> Jabber IM: fd0man at livejournal.com
>
>
> Demand Freedom!  Use /open/ and /free/ protocols, standards, and
> software!
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale
>   




More information about the Ale mailing list