LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 12-01-2011, 07:10 AM   #1
arjun_arippa
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.

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

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


Reply


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


All times are GMT -5. The time now is 03:41 PM.

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