All,
I have an file in the xml format which looks like this
<source>Please wait. This may take several minutes...</source>
<translation>Please wait. This may take several minutes...</translation>
<source>Your computer must be restarted to complete setup.\nClick on 'OK' button to restart.</source>
<translation>Your computer must be restarted to complete setup.\nClick on 'OK' button to restart.</translation>
<source>'%1' can not be deleted. Close all programs\nand try again</source>
<translation>'%1' can not be deleted. Close all programs\nand try again</translation>
<source>XYZ\nCopyright 2005, ABC\nAll rights reserved</source>
<translation>XYZ\nCopyright 2005, ABC.\nAll rights reserved.</translation>
\n are the new line characters. My intention is to replace all \n with an actual new line for the translation tag alone.
I have a sed command for that
sed -e '/<translation>/{
s/\(.*\)\\n\(.*\)\\n\(.\)/\1\n\2\n\3/g
s/\(.*\)\\n\\n\(.\)/\1\n\n\2/g
s/\(.*\)\\n\(.*\)/\1\n\2/g
}' sample.ts
The output is
[/tmp]$ sed -e '/<translation>/{
> s/\(.*\)\\n\(.*\)\\n\(.*\)/\1\n\2\n\3/g
> s/\(.*\)\\n\\n\(.*\)/\1\n\n\2/g
> s/\(.*\)\\n\(.*\)/\1\n\2/g
> }' sample.ts
<source>Please wait. This may take several minutes...</source>
<translation>Please wait. This may take several minutes...</translation>
<source>Your computer must be restarted to complete setup.\nClick on 'OK' button to restart.</source>
<translation>Your computer must be restarted to complete setup.
Click on 'OK' button to restart.</translation>
<source>'%1' can not be deleted. Close all programs\nand try again</source>
<translation>'%1' can not be deleted. Close all programs
and try again</translation>
<source>XYZ\nCopyright 2005, ABC\nAll rights reserved</source>
<translation>XYZ
Copyright 2005, ABC.
All rights reserved.</translation>
It works fine.
Now, the sed command looks pretty complex even though it is simple. Can that sed be simplified ? I am biased towards sed because, I came up with that.
Is there a non-sed solution as well ?
Thanks,
vino