File count from where it left??

i have this code

num=1
dat10=`date "+%m/%d/%Y"  -d "+10 days"`
dat=`date "+%m/%d/%Y"`
set -x
grep "text=.&" /root/Softwares/apache-tomcat-5.5.30/logs/catalina.out|awk -F"from=" '{print $2}'|awk -F"opid" '{print $1}'|sort|uniq > pnos

while read line
do
psql -U poss -d emsver -c "insert into ent(phone_number) values ('$line');"
grep "text=.&" /root/Softwares/apache-tomcat-5.5.30/logs/catalina.out|grep $line|awk -F"text=" '{print $2}'|awk -F "&from" '{print $1}' > services
while read sline
do
psql -U poss -d emsver -c "insert into uiotion(phone_number,service_name,start_date,end_date,last_content_deliver_time) values ('$line','$sline','$dat','$dat10',current_date);"
done < services
num=`wc -l pnos|awk '{print $2}'`
done < pnos

[/CODE]

pnos file contains

2132421
3124321421
4214242424
4242421421

[/CODE]

so once the code iterates the pnos times i want it to iterate next time from where it left for example pnos have 5 lines in it, nect time wn it is iterating it shul iterate from 6th line it shul not strt fm the 1st line.....

I can't really test this, but I think it will work, if I understand the question:

pnos_save_file=$HOME/pnos_save_file.txt
num=1
dat10=`date "+%m/%d/%Y"  -d "+10 days"`
dat=`date "+%m/%d/%Y"`
set -x
grep "text=.&" /root/Softwares/apache-tomcat-5.5.30/logs/catalina.out|awk -F"from=" '{print $2}'|awk -F"opid" '{print $1}'|sort|uniq > pnos

if [ ! -f "$pnos_save_file" ]; then
  echo 1 > "$pnos_save_file"
fi

old_start_line=`cat $pnos_save_file`

tail -n +$old_start_line pnos > pnos.tail

while read line
  do
  psql -U poss -d emsver -c "insert into ent(phone_number) values ('$line');"
  grep "text=.&" /root/Softwares/apache-tomcat-5.5.30/logs/catalina.out|grep $line|awk -F"text=" '{print $2}'|awk -F "&from" '{print $1}' > services
  while read sline
    do
    psql -U poss -d emsver -c "insert into uiotion(phone_number,service_name,start_date,end_date,last_content_deliver_time) values ('$line','$sline','$dat','$dat10',current_date);"
    done < services
  num=`wc -l pnos|awk '{print $2}'`
done < pnos.tail

new_start_line=`cat pnos | wc -l`
new_start_line=`expr $new_start_line + 1`
echo $new_start_line > "$pnos_save_file"
1 Like

thanks hanson :slight_smile: it worked :slight_smile:

Great! I'm really glad to hear that. :b: