help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Printing sections from files with sed


From: Hans Lonsdale
Subject: Re: Printing sections from files with sed
Date: Tue, 31 Jan 2023 08:38:13 +0100 (CET)


> ----------------------------------------
> From: Kerin Millar <kfm@plushkava.net>
> Date: Jan 31, 2023, 7:18:52 PM
> To: Hans Lonsdale <hanslonsdale@mailfence.com>
> Cc: Help Bash <help-bash@gnu.org>
> Subject: Re: Printing sections from files with sed
> 
> 
> On Tue, 31 Jan 2023 07:49:02 +0100 (CET)
> Hans Lonsdale <hanslonsdale@mailfence.com> wrote:
> 
> > Here I set the matching patterns and call sed 
> > 
> > 
> >       pn_ere='^[[:space:]]*([#;!]+|@c|//)[[:space:]]'
> 
> This contains unescaped slashes.
> 
> >       beg_re="${pn_ere}${faml} \[${asmb}\][[:space:]]*$"
> >       end_re="${pn_ere}END OF ${faml} \[${asmb}\][[:space:]]*$"
> > 
> >       sed -n "/$beg_re/,/$end_re/ {
> >           /$beg_re/d ; /$end_re/z; s/${pn_ere}// ; p
> 
> The s command here is using the slash as a delimiter.

What I am trying to do with the "s/${pn_ere}//" is to remove the ## at the 
beginning 
of the lines.  In case where I have // for C++ code.  Looks like the use of "/" 
in "s/${pn_ere}//"
would not be a good option and would have to use a different delimiter.  What 
alternative could I use 
that would be quite safe to use? 
 
> Additionally, sed expects BREs unless given the -E option.
> 
> -- 
> Kerin Millar
> 


-- 
Sent with https://mailfence.com  
Secure and private email



reply via email to

[Prev in Thread] Current Thread [Next in Thread]