Re: Sed reqular expression
On 11/11/2007 5:18 PM, Lars Schouw wrote:
[ final request - PLEASE stop top-posting! Fixed below, again ]
> On Nov 11, 1:56 am, Ed Morton <mor...@lsupcaemnt.com> wrote:
>
>>On 11/10/2007 5:57 AM, Lars Schouw wrote:
>>
>>[ please don't top-post and please provide enough context for your post to
>>stand-alone, fixed below ]
>>
>>
>>
>>
>>
>>
>>>Lars Schouw wrote:
>>
>>>>How do I rename a lot of source code using sed?
>>>
>>>>before foo_test_1(var_test t)
>>>>after FooTest1(varTest t)
>>>
>>>>or if that is to diffcult
>>>>FooTest1(VarTest t)
>>>
>>>You're severely restricting the responses you get by insisting on a
>>>"sed" solution, so if that isn't really a requirement, let us know.
>>
>>>Ed,
>>>No, any solution is fine.. OS also fee Unix or Windows.
>>>Do you have something smart?
>>
>>It depends what your input file looks like. You showed us what you want to do
>>with that symbol, but without knowing what context it appears in in your input
>>file, it's hard to know what type of solution will work without messing up the
>>rest of your file. Show a small, real, sample input and expected output.
>>
>> Ed.- Hide quoted text -
>>
>>- Show quoted text -
>
> Ed,
>
> Like this:
>
>
> before:
> typedef hnd<X_Y> X_Y;
> bool is_a_Z(const X_Y& inst) { return inst.isA<Z>(); }
>
>
> after:
> typedef hnd<XY> XY;
> bool IsAZ(const XY& inst) { return inst.IsA<Z>(); }
>
You'd indicated earlier that you had some flexibility in names:
> before foo_test_1(var_test t)
> after FooTest1(varTest t)
>
> or if that is to diffcult
> FooTest1(VarTest t)
If so, then maybe this solution is adequate:
$ cat file
typedef hnd<X_Y> X_Y;
bool is_a_Z(const X_Y& inst) { return inst.isA<Z>(); }
$ cat cvt.awk
BEGIN{FS=OFS=""}
{
p = ""
for (i=1;i<=NF;i++) {
if (p == "_")
$i = toupper($i)
p = $i
if ($i == "_")
$i = ""
}
}
1
$ awk -f cvt.awk file
typedef hnd<XY> XY;
bool isAZ(const XY& inst) { return inst.isA<Z>(); }
If not, it'd require a little different approach...
Regards,
Ed
|