I have several XML files named TC_Circle1
, TC_Circle2
, `TC_Point1, etc in a directory and I want to use a script to update the start and stop dates in each file. The start and stop dates are inside and tags in each file.
I had a script that worked when we were using Sun machines but it is not working on the new HP Linux machines. It doesn't show any errors and doesn't change the dates. I need help getting it to work in Linux. The script:
#!/usr/local/bin/perl
$numArgs = @ARGV;
if ($numArgs != 2)
{
print "Usage: replace_default_date.pl DEFAULT_START_DATE DEFAULT_STOP_DATE\n";
}
@filenames = `ls TC*`;
chomp(@filenames);
foreach $file (@filenames)
{
open(REGFILE, "$file") || die "Cannot open |$file|";
@lines = <REGFILE>;
close(REGFILE);
open(WRITEFILE), ">$file") || die "Cannot open |$file|";
foreach $line (@lines)
{
if ($line =~ /DEFAULT_START_DATE/)
{
$newline = " " . $ARGV[0];
print WRITEFILE "$newline\n";
}
elsif ($line =~ /DEFAULT_STOP_DATE/)
{
$newline = " " . $ARGV[1];
print WRITEFILE "$newline\n";
}
else
{
print WRITEFILE "$line\n";
}
}
close (WRITEFILE);
}
Here's how the files to be modified look at the beginning:
<RequestSomething xmlns="http://something.com/accessservice">
<period xmlns="">
<start>2013-03-06T00:00:00</start>
<stop>2013-03-07T00:00:00</stop>
</period>
... The rest of the xml file...
</RequestSomething>
Thanks in advance, Crystal
'ls TC*'
with single quotes, not with backquotes, which would be required to run the string as a shell command?