Urgent Help needed please


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Urgent Help needed please
# 1  
Old 06-02-2010
Error 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

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

Thanks in advance
Renjesh Raju

Last edited by pludi; 06-02-2010 at 05:04 AM.. Reason: code tags, please...
# 2  
Old 06-02-2010
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.
Code:
grep -i "A17" examp.txt

# 3  
Old 06-02-2010
No need to cature pattern, but need to make sure that if A17 is the last updation, then do some task. For eq

Code:
#^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

Last edited by pludi; 06-02-2010 at 05:05 AM..
# 4  
Old 06-02-2010
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

Code:
# ^ A **

# 5  
Old 06-02-2010
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.

Code:
#^ 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
#
###############################################################################

Moderator's Comments:
Mod Comment Please use CODE tags, ty

Thanks a lot

Last edited by pludi; 06-02-2010 at 05:05 AM..
# 6  
Old 06-02-2010
Check if this works for you,

Code:
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

# 7  
Old 06-02-2010
Another way :
Code:
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Urgent Help needed...

Hi I want to create a script which deleted files in the following folders older than 30 days. There are a particular version of files inside it to be deleted Folders : /files0/interfaces/ResponsysSavedList/BackInStock/EmailContent/backup... (3 Replies)
Discussion started by: Scudza
3 Replies

2. Programming

URGENT HELP NEEDED

KING KONG ELECTRICITY AUTHORITY BILL CALCULATOR You are required to develop a script that will enable KING KONG ELECTRICITY AUTHORITY to calculate customer bills based on their meter readings. The customers are categorized into the following categories:  Residential customers  Commercial... (1 Reply)
Discussion started by: watisevil
1 Replies

3. Shell Programming and Scripting

Urgent Help needed !!!

Hi, I have a directory, where i get 4 files for each day... The files will be generated at any time. I am trying for a shell script for copying the file from this directory whenever new file is generated. Say for example : If the directory X has following files A1,A2,A3,A4,B1,B2,B3,B4...... (2 Replies)
Discussion started by: krishh.kk
2 Replies

4. UNIX for Dummies Questions & Answers

Urgent Help Needed

Hello Friends, I am a Graduate in Computers. I completed BCA degree this year. I want to make my career in UNIX. But, unfortunately I don't know anybody who can guide me. I am totally confuse because I don't know where to start and what are the future prospect in UNIX. Please give your... (4 Replies)
Discussion started by: Luckyless
4 Replies

5. Shell Programming and Scripting

Urgent Help Needed.

Hi, Below is my issue which I desperately need and I want a shell script which can do this job. I need this script as I m planning to put this for a system health check. Please assist me. 1. There are 10 log files in a particular location. 2. open each log file. Goto to the end of the... (1 Reply)
Discussion started by: kashriram
1 Replies

6. UNIX for Advanced & Expert Users

Urgent help needed!!!

-------------------------------------------------------------------------------- hy guys, i got few interview questions i need someone to answer urgently: 1)If you cant get to the root, you try to fsck it, but gets errors to read file systems. What steps do you take to recover the host... (1 Reply)
Discussion started by: charneet
1 Replies

7. Windows & DOS: Issues & Discussions

Urgent XP help needed Please

Hi, Please accept my apologies if I have not explained anything clearly enough but i am a little old on new lingo!!! I am running XP from home and last night the following happened. After being logged on for pretty much the full day, I had what seemed like a pop up come up. Although most pop... (3 Replies)
Discussion started by: nike1601
3 Replies

8. Shell Programming and Scripting

urgent needed

hi i want solution regarding usage of array. i m having code which is written using if- elif and can i use or access using arrays. here i wana use array values along with if -elif condition. i dnt wana use command line argument parameter1=(scram no_scram) if ; then ... (0 Replies)
Discussion started by: manish1
0 Replies

9. Shell Programming and Scripting

urgent help needed.

Ok I admit it I am stumped and I would appreciate any and all help Here is what I am trying to do. Korn Shell script I am setting a variable to another shell script that I want to invoke in my main script like so: GETDIR=/vol100/cfg/.getdir The .getdir shell script take a parameter,... (4 Replies)
Discussion started by: Batch
4 Replies

10. Shell Programming and Scripting

urgent help needed !!

i have a script, which is continuously looping. i want to view the script name when i use ps command... it is only showing -sh ... UID PID PPID C STIME TTY TIME COMMAND informix 8533 20923 0 18:19:28 pts/ta 0:00 -sh but i dont have my scriptname displayed .... how can i do that my script is... (0 Replies)
Discussion started by: guhas
0 Replies
Login or Register to Ask a Question