add new line after an xml tag

sunshine737
sunshine737 used Ask the Experts™
on
Hi,
I want to add a new line after a tag </Close>  in a file.

i tried the command.but not working
sed 's/</Close>/&\n\//g' sourcefile.txt  > targetfile.txt
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
Thanks for your help.
Most Valuable Expert 2014
Top Expert 2015
Commented:
sed 's#</Close>#&\
#g'

perl -pe 's#(</Close>)#$1\n#gi'

Author

Commented:
i got the error when used perl command.
syntax error at -e line 1, next token ???
Execution of -e aborted due to compilation errors.

I want to add new line, after tag </Close>  in entire file.


Thanks
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

ozo
Most Valuable Expert 2014
Top Expert 2015

Commented:
Are you sure you used the correct perl command?
did you try the sed command?

Author

Commented:
sorry ozo,
perl command is working perfectly.

It was my mistake that,i added char ">" before the command.

Thanks

Author

Commented:
Is it possible with sed command in a single line?

Author

Commented:
Hi Ozo,

The command you provided is removing the tag </Close>

I still need the tag </Close> , in addition to newline before the xml tag.

Can you please help me?

Thanks
ozo
Most Valuable Expert 2014
Top Expert 2015

Commented:
did you include the $1 in the perl command, or the & in the sed command?
another way to do it without the $1 would be
perl -pe 's#(?<=</Close>)#\n#gi' sourcefile.txt  > targetfile.txt

Author

Commented:
problem solved.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial