Dear All,
I have a template xml file like below.
....Some---Header.......
<SignalPreference>
...
<SignalName>STRING</SignalName>
...
</SignalPreference>
......Some formatting text.......
<SignalPreference>
.........
<SignalName>STRING</SignalName>
</SignalPreference>
....Some footer text......
I want to create an actual .xml like below.
For 2 instances of my signals output shown below, preserving all header, footer and other formatting tags.
....Some---Header....... ## Must preserve all the header tags
<SignalPreference>
... #Must preserve this part as it is
<SignalName>STRING1</SignalName>
... #Must preserve this part as it is
</SignalPreference>
<SignalPreference>
... #Must preserve this part as it is
<SignalName>STRING2</SignalName>
... #Must preserve this part as it is
</SignalPreference>
......Some formatting text....... ### must Preserve this as it is
<SignalPreference>
......... #Must preserve this part as it is
<SignalName>STRING1</SignalName>
......... #Must preserve this part as it is
</SignalPreference>
<SignalPreference>
... #Must preserve this part as it is
<SignalName>STRING2</SignalName>
... #Must preserve this part as it is
</SignalPreference>
....Some footer text...... ### Must preserve this as it is.
where STRING1,STRING2 etc are from one more text file signal.txt.
cat Signal.txt
STRING1
STRING2
........ so on
up to 10000 STRINGS
Currently I am manually replicating the <SignalPreference>.. </SignalPreference> tag portions and replacing <SignalName>STRING </SignalName> with my desired string based on line number using grep and sed commands. But this is becoming a very tedious task as I have many tags to replace with.
Thanks
Sidda
Check out the below example, you should be able to modify it to do what you want:
$ cat t
STRING1
STRING2
STRING3
STRING4
## perl script
print "....Some---Header....... ## Must preserve all the header tags\n";
open ( STRINGS, "</temp/tmp/t") or die ("***Error- Couldn't open file: C:/temp/tmp/t, $!\n");
while ( <STRINGS> ) {
chomp;
print "<SignalPreference>\n";
print " ... #Must preserve this part as it is\n";
print " <SignalName>$_</SignalName>\n";
print " ... #Must preserve this part as it is\n";
print "</SignalPreference>\n";
print "\n";
print "......Some formatting text....... ### must Preserve this as it is\n";
}
close STRINGS;
print "....Some footer text...... ### Must preserve this as it is.\n";
$ test.pl
....Some---Header....... ## Must preserve all the header tags
<SignalPreference>
... #Must preserve this part as it is
<SignalName>STRING1</SignalName>
... #Must preserve this part as it is
</SignalPreference>
......Some formatting text....... ### must Preserve this as it is
<SignalPreference>
... #Must preserve this part as it is
<SignalName>STRING2</SignalName>
... #Must preserve this part as it is
</SignalPreference>
......Some formatting text....... ### must Preserve this as it is
<SignalPreference>
... #Must preserve this part as it is
<SignalName>STRING3</SignalName>
... #Must preserve this part as it is
</SignalPreference>
......Some formatting text....... ### must Preserve this as it is
<SignalPreference>
... #Must preserve this part as it is
<SignalName>STRING4</SignalName>
... #Must preserve this part as it is
</SignalPreference>
......Some formatting text....... ### must Preserve this as it is
....Some footer text...... ### Must preserve this as it is.
Hi Spacebar,
I am working on the perl script you mentioned.
Can you let me know on how to print some text containing
""
in it using perl command
print
. ??
Example: I have below text to be printed with print.
<?xml version="1.0" encoding="utf-8"?>
Except this looks like I can do rest of the things.
Regards
Sidda
You can do it like this:
print '<?xml version="1.0" encoding="utf-8"?>';