Solved

Insert Line between patterns in shell

Posted on 2013-06-17
3
260 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 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Shell Mail is not working 5 124
RoboCopy to Changing External Drives 2 60
bash while loop reading input from data section in script 7 71
AWS CLI issues with Tags 3 94
Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

733 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