Solved

Insert Line between patterns in shell

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

Expert Comment

by:Gerwin Jansen
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…
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.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now