I have a small requirement
How to get patterns between string this way
Input..
05 ABC.
TAGTAG 10 AAA PIC 9
10 BBB PIC X
COMMET 10 CCC COMP PIC 9
05 DEF
I wanted to get all the variable between 05 ABC and next 05 level
out put should be
AAA
BBB
CCC
For this specific case, what is your definition of a 'variable'?
it a cobol code..
TAGTAG 10 AAA PIC 9
10 BBB PIC X
[ ]COMMET 10 CCC COMP PIC 9
05 DEF
1st six chars can be anything followed by some spaces
followed by some 2 digit numeric followed by a varible name... followed COMP or just a PIC
sed -n '/^05 ABC/,/^05/p' input_file | sed '1d;$d' | \
while read mLine
do
mVar=`echo $mLine | sed -e 's/.*[0-9]\{2\} \(.*\) .*/\1/' -e 's/ .*//'`
echo "mVar = "$mVar
done
thanks...
i was trying with awk '/^05 ABC/,/^05/' input_file
that didnt work
the sed worked ...
thanks
Small extn to the Previous one
I have Some thing like this
SORT KEY FS-KEY1
###
SORT KEY FS-KEY2
FSKEY3
###
SORT KEY
FS-KEY4
###
Can we get the all the KEY Fields..
It Starts with SORT KEY and the KEY feilds can be in the same line or next line until ### comes
mFound='N'
while read mLine
do
mCnt=`echo $mLine | egrep -c 'SORT KEY'`
if [ "${mCnt}" != "0" ]; then
mFound='Y'
fi
if [ "${mLine}" = "###" ]; then
mFound='N'
fi
if [ "${mFound}" = "Y" ]; then
mOutLine=`echo ${mLine} | sed 's/SORT KEY//'`
if [ "${mOutLine}" != "" ]; then
echo "Key = "${mOutLine}
fi
fi
done < input_file