Urgent Help needed please

Hi,

I have a small grepping problem in my script.I am having a file from which i need to make sure "#^A17" is the last updation (Next # can be ignored) before ################.The idea behind this is, if this file contains "A17" as the last updation, i need to do a particular activity. please help me out in this as this is an urgent requirement. I want to make a loop in such a way that if "A17" is the last updation, i need to do a task.

I am attaching that lines from the file

#                   skdjghskdghjkg
#^ A17  03/04/10    sdlkgjlsdkgjsdklgjklsdj                         skldgsdljgk
#
###############################################################################

Thanks in advance
Renjesh Raju

i have a small question. do u need to capture #^A17 or wil it be solved #A17 .. please let me knw

---------- Post updated at 02:39 AM ---------- Previous update was at 02:30 AM ----------

if this can be done with A17 (i mean u just need to see if A17 can be printed then use below command.

grep -i "A17" examp.txt

No need to cature pattern, but need to make sure that if A17 is the last updation, then do some task. For eq

#^A17 s;ldgk;sldgk
#^A18 sa;fkl;algklk
#
##############################

if this is the condition(After A17 one more Pattern occured), I want to do something else like that ...

if A17 is the last occurence then do this

otherwise do that

Thanks

so basically u want the last line ??? dont u ?!

---------- Post updated at 02:51 AM ---------- Previous update was at 02:48 AM ----------

waht i meant was last line with a output like

# ^ A **

Yes. But that was not the end of the file, it is just the end of the commending part. For clarification, i will paste more part of the file.

#^ A14  02/11/2010  Changed ksh back to sh                           D.Chesmore
#^ A15  02/17/2010  Changed linux rh5 grep to include only su        D.Chesmore
#^ A16  02/17/2010  adjust REPORT.reduced logic                      Heermance
#                   fixed one of Dan's lines
#^ A17  03/04/10    Fully qualify st00ctrl                           Hartsock
#
###############################################################################

Thanks a lot

Check if this works for you,

NUM=$(awk '/^#\^ A[0-9]+/ {C=$2} END {print C}' file)

if [ "$NUM" = "A17" ]; then
  echo "last comment is A17"
else
  echo "last comment is something else"
fi

Another way :

chk='A17'

awk '
   /#\^ / {upd=$2}
   END {if ($upd) exit (tolower(upd)==tolower(check) ? 10 : 11)}
' check=$chk inputfile
sts=$?

case $sts in
  10) echo "'$chk' is the last update."    ;;
  11) echo "'$chk' isn't the last update." ;;
   9) echo "Update id not found!."         ;;
   *) echo "Error!"                        ;;
esac

Jean-Pierre.

Yaa , its working fine.

Guyz thanks a lot of your quick reply....

Renjesh Raju

---------- Post updated at 04:00 PM ---------- Previous update was at 03:52 PM ----------

Thank a lot guyz ....
its working perfectly fine.

Renjesh Raju

---------- Post updated at 04:01 PM ---------- Previous update was at 04:00 PM ----------

Its working fine

Thanks a lot

Renjesh Raju