Hello
I have a input file called xaa, i want to extract the lines between if & fi including if & fi from the input file and assign each group of lines that match that search pattern to an array or variable.
The idea is so I can search a group of scripts and find all the instances of if & fi condition, return the script name and assign each group of lines to a variable or an array, which is every better
So far all i can get is the output of the search, I am a bit stumped on what to do next or the best way to go about this. Any help or pointers anyone can give me , would be much appreciated.
>awk -f 6.awk xaa
if [ -z $TOP ]
then
echo " TOP empty"
fi
if
34
fi
-=-=-=-
ideal output, something on these lines
-=-=-=-=-=-=
<script name> two instances of if & fi found
instance1
if [ -z $TOP ]
then
echo " TOP empty"
fi
instance 2
if
34
fi
-=-=-=-=-=-=-=-
# xaa input file or any script that contains if & fi statements
if [ -z $TOP ]
then
echo " TOP empty"
fi
if
1 2 3
4 5 6
when
if
then
stop
if
34
fi
if fi
-=-=-=-=
6.awk file
=-=-=-==
#nawk -f 6.awk xaa > out.xaa
BEGIN {
FS="\$"
}
#awk
/^if/{t=0}
{a[++t]=$0}
/^fi/{for(i=1;i<=t;++i)print a}
-=-=-=-=-=-=
I have a input file called xaa, i want to extract the lines between if & fi including if & fi from the input file and assign each group of lines that match that search pattern to an array or variable.
The idea is so I can search a group of scripts and find all the instances of if & fi condition, return the script name and assign each group of lines to a variable or an array, which is every better
So far all i can get is the output of the search, I am a bit stumped on what to do next or the best way to go about this. Any help or pointers anyone can give me , would be much appreciated.
>awk -f 6.awk xaa
if [ -z $TOP ]
then
echo " TOP empty"
fi
if
34
fi
-=-=-=-
ideal output, something on these lines
-=-=-=-=-=-=
<script name> two instances of if & fi found
instance1
if [ -z $TOP ]
then
echo " TOP empty"
fi
instance 2
if
34
fi
-=-=-=-=-=-=-=-
# xaa input file or any script that contains if & fi statements
if [ -z $TOP ]
then
echo " TOP empty"
fi
if
1 2 3
4 5 6
when
if
then
stop
if
34
fi
if fi
-=-=-=-=
6.awk file
=-=-=-==
#nawk -f 6.awk xaa > out.xaa
BEGIN {
FS="\$"
}
#awk
/^if/{t=0}
{a[++t]=$0}
/^fi/{for(i=1;i<=t;++i)print a}
-=-=-=-=-=-=