Hi All,
I have a file content like this.
#<clear_category_list>
#<include file="SUITE:Provision-FLEXPONDER_FAC.inc">
#<include file="CAT:SYSTEM:SAS_U23.inc">
#<include file="CAT:PRIORITY:10.inc">
#<include file="CAT:FAC_TYPE:OC48.inc">
#<include file="CAT:FAC_TYPE:OC192.inc">
#<include file="CAT:FAC_TYPE:OCH107.inc">
#<include file="CAT:FAC_TYPE:OCH111.inc">
#<include file="CAT:FAC_TYPE:OCN.inc">
#<include file="CAT:FAC_TYPE:10GE.inc">
#<include file="CAT:CARD_TYPE:IFMA-BU.inc">
#<include file="CAT:BOARD_TYPE:cpp8548.inc">
#<include file="CAT:SCHEDULER:2.inc">
#--------------------------------------------------------------
#<testcase_begin testcase_id="SAS_U23_FAC10_Regression">
testcase_title="SAS_U23 FAC10 Regression">
Where i can search only by using the pattern "SAS_U23_FAC10_Regression"
There are lots of content in this file.
What i want is to change the line
#<include file="CAT:PRIORITY:10.inc">
to
#<include file="CAT:PRIORITY:3.inc">
and i want to count of how many i have changed, I also want the count like if it is already changed or not,
I have tried the below code to find the pattern match, and i could not proceed further, can u all pls guide?
#!/bin/perl
open(fp, "<file_name");
while(<fp>)
{
$line = $_;
my $N = 1; # Number of lines before matching line.
my $PATTERN = "SAS_U23_FAC10_Regression"; # What you want to match.
my @buffer;
while (my $line = <fp>) {
if (@buffer < $N) {
push @buffer, $line;
next;
}
if ($line =~ /$PATTERN/) {
print $buffer[0];
}
shift @buffer;
push @buffer, $line;
}
}
Could this help you ?
perl -nle 'BEGIN{$count=0;$cnt=0} if(/#\<include file="CAT:PRIORITY:3.inc"\>/) { ++$count}
if(/#<include file="CAT:PRIORITY:10.inc">/) {s/#<include file="CAT:PRIORITY:10.inc">/#<include file="CAT:PRIORITY:3.inc">/;
++$cnt; }
print $_;
END { printf "count changed now - $cnt\nCount Already Changed - $count\n";}' filename
Thanks for the help,
but i have a file content like this,
#==============================================================
#<clear_category_list>
#<include file="SUITE:Security-Security.inc">
#<include file="CAT:SYSTEM:U75_U23.inc">
#<include file="CAT:PRIORITY:1.inc">
#<include file="CAT:FAC_TYPE:DEFAULT.inc">
#<include file="CAT:CARD_TYPE:MPMA-SHP3.inc">
#<include file="CAT:BOARD_TYPE:cpp8548.inc">
#<include file="CAT:SCHEDULER:3.inc">
#--------------------------------------------------------------
#<testcase_begin testcase_id="U75_U23_User_Security_Test">
testcase_title="U75_U23 User Security Test">
#<testcase_requirements requirement_id="REGRESSION_REQ_ID">
#<testcase_script script="run_regression_usersec -findboard ${BOARD_TYPE} -next -stop -var SYSTEM ${CATEGORY_SYSTEM} -schedule +${SCHEDULER}h ">
#<testcase_objectives_begin>
test the FEATUREGROUP feature for FEATURE for CARDTYPE
#<testcase_objectives_end>
#<testcase_setup_begin>
#<testcase_setup_end>
#<testcase_procedure_begin>
#<testcase_procedure_end>
#<testcase_expected_results_begin>
#<testcase_expected_results_end>
#<testcase_end>
#==============================================================
#<clear_category_list>
#<include file="SUITE:SAS_HK_MR537_Reg.inc">
#<include file="CAT:SYSTEM:SAS_U23.inc">
#<include file="CAT:PRIORITY:1.inc">
#<include file="CAT:FAC_TYPE:DEFAULT.inc">
#<include file="CAT:CARD_TYPE:DEFAULT.inc">
#<include file="CAT:BOARD_TYPE:cpp8548.inc">
#<include file="CAT:SCHEDULER:1.inc">
#--------------------------------------------------------------
#<testcase_begin testcase_id="SAS_U23_HK_MR537_Regression_Test">
testcase_title="SAS_U23 HK MR537 Regression">
#<testcase_requirements requirement_id="REGRESSION_REQ_ID">
#<testcase_script script="run_regression_hk_r71 -findboard ${BOARD_TYPE} -next -stop -var SYSTEM ${CATEGORY_SYSTEM} -schedule +${SCHEDULER}h ">
#<testcase_objectives_begin>
test the FEATUREGROUP feature for FEATURE for FACTYPE
#<testcase_objectives_end>
#<testcase_setup_begin>
#<testcase_setup_end>
#<testcase_procedure_begin>
#<testcase_procedure_end>
#<testcase_expected_results_begin>
#<testcase_expected_results_end>
#<testcase_end>
wheer i should search for the testcase based on the various "testcase_begin testcase_id" present, and then move up to search the keyword PRIORITY:10 or any number and then change it as PRIORITY:3
And then find the count.