It will show only the particular line which contains abc100.
I want the function name which contains 'abc100' and other other numbers which having the same pattern 'RA '.
I tried the following
awk -F"RA " '{ print $2}' $FileName | awk '{print $1}'| sed 's/[-+;:!=?"|{}()<>~\%\$\@\#\^\&\*\[\\\/]/ /g' | sed '/^$/d' | uniq
it will list out all the strings with pattern "RA " in the file.
I just want to know the function name which contains the specific string, and the line numbers of starting of the function and ending of the function.
here's the code with some comments to try to explain...i hope it helps..
$str=shift @ARGV;
while(<>){
# match function name and save name and line to display later in
# case the RA is found
if(!$sw && /(.+\(.*\))/){
$func_name=$1;
$func_start=$.;
$sw=1;
@ra=();
next;
}
# those counters basically server to know if we are ($c>0) or not ($c==0)
# inside a function body i.e. between { and }
$c++ if $sw && /\{/;
$c-- if $sw && /\}/;
# match RA string and save it in a list
if(/\/\*RA (.+)\*\//){
push(@ra,$1);
}
# flag to know if the RA in questions was found, so we'll preint everything
# we've saved
if(/\/\*RA $str/){
$print=1;
}
# if we are at the end of a function $sw==1 and $c==0 then
if($sw && $c==0){
# we test if any of the RAs in the function was the one we were
# looking for, if so print all the elements
if($print){
print "function $func_name\n";
print "start line $func_start\n";
print "end line $.\n";
print "ra's:\n ".join("\n ",@ra)."\n";
$print=0;
}
$sw=0;
}
}