Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 12-01-2011, 07:10 AM   #1
LQ Newbie
Registered: Dec 2011
Posts: 1

Rep: Reputation: Disabled
Help regarding inserting a new line in an xml using a shell script

Hi..wanted a help regarding inserting a newline in an xml file using shell script.

i've an xml file which has the following data.

1. <?xml version="1.0" encoding="UTF-8"?>
2. <group>
3. <name>odcm</name>
4. contd....

I need to insert two new lines after line#2, so that the output should be,

1. <?xml version="1.0" encoding="UTF-8"?>
2. <group>
3. newline
4. newline
5. <name>odcm</name>
6. contd....

Now that the lines numbers are not the same in all xml files, I would need to grep for <group> tag and then insert the lines after that tag. I tried various options but ended up in vain. Please help in this query.

Tried this: $ sed "/<group>/{G;G;}/" file
but not the exact result.

Thanks in advance.

Old 12-01-2011, 08:27 AM   #2
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
sed '/<group>/a\
' file >newfile
mv newfile file
For GNU sed you can use the -i option:
sed -i '/<group>/a\
' file


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating XML files using a shell script. Cpare Programming 3 04-01-2011 06:16 PM
[SOLVED] How can I use the command line to split a single-lined XML into a multi-line XML xexers Linux - Software 3 12-09-2010 08:25 AM
How to delete lines and insert another line in some xml files using a shell script? luananeko Linux - Newbie 1 07-20-2009 10:53 PM
mp3 filename to xml shell script jason7 Linux - Server 1 03-21-2009 06:22 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:22 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration