The command:
sed '/param-/s/default/different/' file1 > file2
does not work.
Let me frame my question correctly.
I want to get all the lines starting from <init-param> and ending with </init-param> only if the lines between these tags has a "default" keyword.
#!/usr/local/bin/perl
# find_default_tags.pl
my $filename = shift;
open (X_FILE, '<', $filename) or die "Failed to read file $filename : $!";
{
local $/;
while (<X_FILE>) {
while (m#(<init-param>.*?>default<.*?</init-param>)#gs) {
print $1 . "\n";
}
}
}
close (X_FILE);
Thank you Cherry your code did work but with a small change, i changed the $3 to $2 only then i got all the occurances of the <init-param> which has default keyword, with $3 i would get only one occurance.
Yogesh - i am not very good at understanding perl so, i havent been able to try your code. Thanks anyway for the help.
I have one more question to add to this. Actually after getting the output for the list of <init-param> that has default keyword, i need to copy the output to another web.xml file again by searching for the default keyword, but, i want to copy these lines in the web.xml only after the last occurance of the keyword, default within the <init-param>.
So, say i have a file web1.xml from which i used the Sed command given by Cherry and got the output as :
Now i want to paste the above output to another file web2.xml, which also has few <init-param> </init-param> tags, with default keyword. I want to search for the last occurance of the <init-pram>default</init-param> tag which has default keyword and just paste the above output after the last occurance.
Hope Cherry can help me with this also. Actually i am new to SED and AWK commands in unix and am expected by my manager to prepare a script like this, which i cannot untill unless i read the tutorials.
Thanks for the help and waiting for some more help