Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Insert Line between patterns in shell

Posted on 2013-06-17
3
Medium Priority
?
268 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
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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

773 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