another character substitution question

another character substitution question

am 21.08.2007 22:07:48 von PaulS

I have a file where one line looks like this:

+nkf =0.5 dev/gauss={7.5e-19*dkispp*0.01672/sqrt(E(*,m))} rb = 500

I want to remove the text:

dev/gauss={7.5e-19*dkispp*0.01672/sqrt(E(*,m))}

There are many lines in my file with the dev/gauss thing and in each
case the numbers withing the brackets are different>

I thought I'd try this (see below) but it doesn't seem to work:

s 'dev/gauss\*+}'';


my idea was to substitute anything that starts with dev/gauss , has one
or more alphanumeric characters and ends with a closing bracket }



Any tips for how to do this?

Thanks!

Paul

Re: another character substitution question

am 21.08.2007 22:20:47 von Mirco Wahab

pauls wrote:
> I have a file where one line looks like this:
> +nkf =0.5 dev/gauss={7.5e-19*dkispp*0.01672/sqrt(E(*,m))} rb = 500
> I want to remove the text:
> dev/gauss={7.5e-19*dkispp*0.01672/sqrt(E(*,m))}
> I thought I'd try this (see below) but it doesn't seem to work:
> s 'dev/gauss\*+}'';

The \* is not correct. You meant probably .* ('.' means any character).

In Linux/Unix, you could do a:

perl -pe 's/dev\/gauss[^}]+}//' gauss.txt > nogauss.txt

Regards

M.

Re: another character substitution question

am 21.08.2007 22:23:19 von Klaus

On Aug 21, 10:07 pm, pauls wrote:
> I have a file where one line looks like this:
>
> +nkf =0.5 dev/gauss={7.5e-19*dkispp*0.01672/sqrt(E(*,m))} rb = 500
>
> I want to remove the text:
>
> dev/gauss={7.5e-19*dkispp*0.01672/sqrt(E(*,m))}
>
> There are many lines in my file with the dev/gauss thing and in each
> case the numbers withing the brackets are different>
>
> I thought I'd try this (see below) but it doesn't seem to work:
>
> s 'dev/gauss\*+}'';
>
> my idea was to substitute anything that starts with dev/gauss , has one
> or more alphanumeric characters and ends with a closing bracket }

If you don't have nested { ... }, then the following should work:

s!dev/gauss={[^}]*?}!!g;

On the other hand, if you do have nested { ... }, then you will have
to read first perlfaq 4: "How do I find matching/nesting anything?"

--
Klaus

Re: another character substitution question

am 21.08.2007 22:35:30 von Gunnar Hjalmarsson

pauls wrote:
> I have a file where one line looks like this:
>
> +nkf =0.5 dev/gauss={7.5e-19*dkispp*0.01672/sqrt(E(*,m))} rb = 500
>
> I want to remove the text:
>
> dev/gauss={7.5e-19*dkispp*0.01672/sqrt(E(*,m))}
>
> There are many lines in my file with the dev/gauss thing and in each
> case the numbers withing the brackets are different>
>
> I thought I'd try this (see below) but it doesn't seem to work:
>
> s 'dev/gauss\*+}'';

s'dev/gauss\S+''

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Re: another character substitution question

am 21.08.2007 22:44:58 von PaulS

Klaus wrote:
> On Aug 21, 10:07 pm, pauls wrote:
>> I have a file where one line looks like this:
>>
>> +nkf =0.5 dev/gauss={7.5e-19*dkispp*0.01672/sqrt(E(*,m))} rb = 500
>>
>> I want to remove the text:
>>
>> dev/gauss={7.5e-19*dkispp*0.01672/sqrt(E(*,m))}
>>
>> There are many lines in my file with the dev/gauss thing and in each
>> case the numbers withing the brackets are different>
>>
>> I thought I'd try this (see below) but it doesn't seem to work:
>>
>> s 'dev/gauss\*+}'';
>>
>> my idea was to substitute anything that starts with dev/gauss , has one
>> or more alphanumeric characters and ends with a closing bracket }
>
> If you don't have nested { ... }, then the following should work:
>
> s!dev/gauss={[^}]*?}!!g;
>
> On the other hand, if you do have nested { ... }, then you will have
> to read first perlfaq 4: "How do I find matching/nesting anything?"
>
> --
> Klaus
>
brilliant, that did the trick!

thanks so much for your help, you got me out of a coding impasse!

P.