Hi,
I have the below script:
/opt/app/dstage/DataStage752/Ascential/DataStage/DSEngine/bin/dsjob lprojects >> prj
j=`cat prj|wc -l|sed -e 's/^[ \t]*//'`
for i in {1..$j}
do
pr=head -$i prj
k=`cat status.txt| grep $pr |wc -l|sed -e 's/^[ \t]*//'`
echo "there are $k in $pr" >> body.txt
done
The first line in the script will create a file called 'prj' which contains the belo data:
abc
bcd
cde
So, the j value becomes 3.
so the for loop will execute from 1 to 3.
The file status.txt contains the below data:
1-abc
11-abc
12-abc
1-bcd
0-bcd
1-cde
12-cde
123-cde
So,in the first iteration $pr becomes abc.
While grepping for abc in status.txt there are 3. so $k becomes 3.
So body.txt will get the content as "there are 3 in abc".
In the next iteration, $k becomes 2 (since there are 2 bcd in status.txt).
So the line "there are 2 in bcd" will be appended to body.txt.
But it's not working as expected.
Can any one tell me where i am making mistakes in the script?
Thanks
---------- Post updated at 12:38 PM ---------- Previous update was at 11:25 AM ----------
Silly mistake:
head -1 will work correctly
but while going with head -2 , it causes the failure in grep
---------- Post updated at 12:42 PM ---------- Previous update was at 12:38 PM ----------
In stead of head , i would like to go with sed -n option.
BUt i am getting syntax error for the below code:
pr=`sed -n '$i{p}' prj|sed -e 's/^[ \t]*//'`
can any one help me?
Thanks