Solved

Insert Line between patterns in shell

Posted on 2013-06-17
3
262 Views
Last Modified: 2013-10-03
Hi,
I have following file:

#Start Line: Block about dogs
#End Line: Block about dogs

#Start Line: Block about cats
#End Line: Block about cats


I need  to insert  some text lines (value of variables)  between  pattern "Block about dogs"  and some between "Block about cats"


Thanks
0
Comment
Question by:IKeystone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 39255424
Hi, what have you got already? Pls. post that.
0
 
LVL 5

Accepted Solution

by:
DOSLover earned 500 total points
ID: 39256528
Here is simple way of using sed to achieve this. First of all, please try 'which sed' command to know path to sed command. Typically it will be /usr/bin/sed. But it could be different on your system. Please try the following command (either from command line or in a script):
/usr/bin/sed -e '/#End Line: Block about dogs/i\
  This line goes between Block about dogs
' MySourceFile.txt > MyTargetFile.txt

Open in new window

0
 
LVL 5

Expert Comment

by:magento
ID: 39261799
Hi ,

Check the below post . Same as your request.

http://stackoverflow.com/questions/11694980/using-sed-insert-a-line-below-or-above-the-pattern

BR,

Magento
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question