Unix Shell - sed multiple line match

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > March 2005 > sed multiple line match





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author sed multiple line match
one2001boy@yahoo.com

2005-03-26, 6:05 pm

Hello,

Thanks for the previous help on sed. I have another question about
using sed.
Is there a way to get the following code work?

I have an input file p.h with content below:

extern PNG_EXPORT(png_uint_32,png_access_versio
n_number)
extern PNG_EXPORT(void,
png_set_sig_bytes)
extern PNG_EXPORT(void,
png_out,
png_in,
png_set_sig_bytes)

I want to remove PNG_EXPORT(),the expected the output is:

extern png_uint_32 png_access_version_number
extern void png_set_sig_bytes
extern void png_out png_in png_set_sig_bytes

I created the following p.sed file to handle it, but it doesn't succeed.

/PNG_EXPORT/ {
$!N
s/PNG_EXPORT(\([^,]*\),\([^)].*\))/\1 \2/
P;D
}

any suggestions to make a change to get it work?

Many thanks.
John W. Krahn

2005-03-26, 6:05 pm

one2001boy@yahoo.com wrote:
> Hello,
>
> Thanks for the previous help on sed. I have another question about
> using sed.
> Is there a way to get the following code work?
>
> I have an input file p.h with content below:
>
> extern PNG_EXPORT(png_uint_32,png_access_versio
n_number)
> extern PNG_EXPORT(void,
> png_set_sig_bytes)
> extern PNG_EXPORT(void,
> png_out,
> png_in,
> png_set_sig_bytes)
>
> I want to remove PNG_EXPORT(),the expected the output is:
>
> extern png_uint_32 png_access_version_number
> extern void png_set_sig_bytes
> extern void png_out png_in png_set_sig_bytes
>
> I created the following p.sed file to handle it, but it doesn't succeed.
>
> /PNG_EXPORT/ {
> $!N
> s/PNG_EXPORT(\([^,]*\),\([^)].*\))/\1 \2/
> P;D
> }
>
> any suggestions to make a change to get it work?


You could try Perl:

perl -i -p051e's/PNG_EXPORT\(([^)]+)\)/($a=$1)=~y| \t\n,| |s;$a/e' p.h



John
--
use Perl;
program
fulfillment
Ed Morton

2005-03-26, 6:05 pm



one2001boy@yahoo.com wrote:
> Hello,
>
> Thanks for the previous help on sed. I have another question about
> using sed.
> Is there a way to get the following code work?
>
> I have an input file p.h with content below:
>
> extern PNG_EXPORT(png_uint_32,png_access_versio
n_number)
> extern PNG_EXPORT(void,
> png_set_sig_bytes)
> extern PNG_EXPORT(void,
> png_out,
> png_in,
> png_set_sig_bytes)
>
> I want to remove PNG_EXPORT(),the expected the output is:
>
> extern png_uint_32 png_access_version_number
> extern void png_set_sig_bytes
> extern void png_out png_in png_set_sig_bytes
>
> I created the following p.sed file to handle it, but it doesn't succeed.
>
> /PNG_EXPORT/ {
> $!N
> s/PNG_EXPORT(\([^,]*\),\([^)].*\))/\1 \2/
> P;D
> }
>
> any suggestions to make a change to get it work?
>
> Many thanks.


You already got both a sed and an awk answer to this when you posted it
under the subject line "sed problem". If there's something deficient
about those answers, tell us what it is.

Ed.
one2001boy@yahoo.com

2005-03-26, 6:05 pm

Ed Morton wrote:
>
>
> one2001boy@yahoo.com wrote:
>
>
>
> You already got both a sed and an awk answer to this when you posted it
> under the subject line "sed problem". If there's something deficient
> about those answers, tell us what it is.
>
> Ed.



I just checked. You are right. I thought my previous post is gone since
it never showed up. but it seems that the post is threaded under another
sed topic. Sorry about it.

Thanks for your help.

John W. Krahn

2005-03-30, 7:55 am

one2001boy@yahoo.com wrote:
> Hello,
>
> Thanks for the previous help on sed. I have another question about
> using sed.
> Is there a way to get the following code work?
>
> I have an input file p.h with content below:
>
> extern PNG_EXPORT(png_uint_32,png_access_versio
n_number)
> extern PNG_EXPORT(void,
> png_set_sig_bytes)
> extern PNG_EXPORT(void,
> png_out,
> png_in,
> png_set_sig_bytes)
>
> I want to remove PNG_EXPORT(),the expected the output is:
>
> extern png_uint_32 png_access_version_number
> extern void png_set_sig_bytes
> extern void png_out png_in png_set_sig_bytes
>
> I created the following p.sed file to handle it, but it doesn't succeed.
>
> /PNG_EXPORT/ {
> $!N
> s/PNG_EXPORT(\([^,]*\),\([^)].*\))/\1 \2/
> P;D
> }
>
> any suggestions to make a change to get it work?


You could try Perl:

perl -i -p051e's/PNG_EXPORT\(([^)]+)\)/($a=$1)=~y| \t\n,| |s;$a/e' p.h



John
--
use Perl;
program
fulfillment
Ed Morton

2005-03-30, 7:55 am



one2001boy@yahoo.com wrote:
> Hello,
>
> Thanks for the previous help on sed. I have another question about
> using sed.
> Is there a way to get the following code work?
>
> I have an input file p.h with content below:
>
> extern PNG_EXPORT(png_uint_32,png_access_versio
n_number)
> extern PNG_EXPORT(void,
> png_set_sig_bytes)
> extern PNG_EXPORT(void,
> png_out,
> png_in,
> png_set_sig_bytes)
>
> I want to remove PNG_EXPORT(),the expected the output is:
>
> extern png_uint_32 png_access_version_number
> extern void png_set_sig_bytes
> extern void png_out png_in png_set_sig_bytes
>
> I created the following p.sed file to handle it, but it doesn't succeed.
>
> /PNG_EXPORT/ {
> $!N
> s/PNG_EXPORT(\([^,]*\),\([^)].*\))/\1 \2/
> P;D
> }
>
> any suggestions to make a change to get it work?
>
> Many thanks.


You already got both a sed and an awk answer to this when you posted it
under the subject line "sed problem". If there's something deficient
about those answers, tell us what it is.

Ed.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com