[ale] bash, sed substitution brain baker
Jim Kinney
jim.kinney at gmail.com
Tue Oct 27 14:59:21 EDT 2009
That eval would probably work if I did a line-by-line literal pipe.
I've been testing the awk version and am now building the substitution
map queries
select 'colormap["'color'"]="',color_id'"' from colortable;
On Tue, Oct 27, 2009 at 2:18 PM, JK <jknapka at kneuro.net> wrote:
> Jim Kinney wrote:
>> I have a series of files that are comma delimited
>>
>> abc.com,100,30,70,blue,ipv4,pizza
>>
>> and there are about 4 million entries with various values in the
>> fields. I need to slurp this into a db but I need to substitute fields
>> 5 and 7 with their field ID instead of their value. So I some other
>> shell variables in use:
>> export blue='2'
>> export pizza='7'
>> export red='1'
>> export soup='3'
>> -etc.
>>
>> so as an exercise in sed foo I'm trying to extract the first 4 million
>> line pull, pipe it into a sed call and spit that back into a different
>> db on a different machine doing a substitution on the fly as follows:
>>
>> sed "s/\([a-zA-Z0-9\.]\+\),\([0-9]\+\),\([0-9]\+\),\([0-9]\+\),\([a-zA-Z0-9\.]\+\),\([a-zA-Z0-9\.]\+\),\([a-zA-Z0-9\.]\+\)/\1,\2,\3,\4,"'"${\5}"'",\6,"'"${\7}"'"/"
>>
>> That pile of quotes near the end is double-single-double wrapping each
>> sed variable in braces.
>>
>> It _ALMOST_ works! I get back out:
>>
>> abc.com,100,30,70,"${blue}",10.0.1.2,"${pizza}"
>
>
> So if you take that result string (call it $STR) and do:
>
> eval echo $STR
>
> you ought to get the string you want. It's not exactly pretty,
> and no substitute for actually knowing WTF is up with that (I admit
> I don't!), but it should work. (I'm just trying to hill-climb from
> where you are to where you wanna be, without actually parsing that
> psychotic sed command.)
>
> -- JK
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
>
--
--
James P. Kinney III
Actively in pursuit of Life, Liberty and Happiness
More information about the Ale
mailing list