dbaspot
Tags Register FAQ Calendar Search Today's Posts Mark Forums Read

SED question: Inserting a blank line - shell

This is a discussion on SED question: Inserting a blank line - shell ; I have a SED file that replaces a bunch of stuff. In one line I am trying to add a blank line in the target text file after the following word at the beginning of a line: "BY" My expression ...


Home > Database Forum > Operating Systems > shell > SED question: Inserting a blank line

Reply

 

LinkBack Thread Tools Display Modes
  #1  
Old 11-12-2008, 01:53 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default SED question: Inserting a blank line

I have a SED file that replaces a bunch of stuff. In one line I am
trying to add a blank line in the target text file after the
following word at the beginning of a line:

"BY"


My expression is as follows:


s/^BY*$/BY*$\
/

When I run SED on the target text file I get the following error
message:


sed: 42: scripts/ppsedf: unterminated regular expression

(my_sed executable file calls the my_sedf).


What should I do?


If it matters, I am on a system using Open BSD.


Thanks,


Deguza


Reply With Quote
  #2  
Old 11-12-2008, 02:23 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: SED question: Inserting a blank line

At 2008-11-12 12:53PM, "Kompu Kid" wrote:
> I have a SED file that replaces a bunch of stuff. In one line I am
> trying to add a blank line in the target text file after the
> following word at the beginning of a line:
>
> "BY"


Instead of search and replace, try triggering an action when that
pattern is seen:

printf "%s\n" A B BY C D | sed '/^BY/a
'

Or, using awk:

printf "%s\n" A B BY C D | awk '1{print}/^BY/{print ""}'



--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
Reply With Quote
  #3  
Old 11-12-2008, 03:17 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: SED question: Inserting a blank line

2008-11-12, 18:23(+00), Glenn Jackman:
> At 2008-11-12 12:53PM, "Kompu Kid" wrote:
>> I have a SED file that replaces a bunch of stuff. In one line I am
>> trying to add a blank line in the target text file after the
>> following word at the beginning of a line:
>>
>> "BY"

>
> Instead of search and replace, try triggering an action when that
> pattern is seen:
>
> printf "%s\n" A B BY C D | sed '/^BY/a
> '

[...]

or ... | sed '/^BY/G'


--
Stéphane
Reply With Quote
  #4  
Old 11-12-2008, 07:18 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: SED question: Inserting a blank line

On Nov 12, 9:53*am, Kompu Kid wrote:
> I have a SED file that replaces a bunch of stuff. In one line I am
> trying to add a blank line in the target text file after the
> following word at the beginning of a line:
>
> "BY"
>
> My expression is as follows:
>
> s/^BY*$/BY*$\
> /
>
> When I run SED on the target text file I get the following error
> message:
>
> sed: 42: scripts/ppsedf: unterminated regular expression
>
> (my_sed executable file calls the my_sedf).
>
> What should I do?
>
> If it matters, I am on a system using Open BSD.
>
> Thanks,
>
> Deguza


Thanks for all those who answered. I inserted

/^BY/G

into my my_sedf file and it seems to do the trick.

Deguza
Reply With Quote
Reply

Thread Tools
Display Modes



All times are GMT -4. The time now is 03:43 PM.