File contents parsing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File contents parsing
# 1  
Old 10-24-2006
Question File contents parsing

Suppose I have a file which has either the contents
Code:
CALLED on <date & time>
RUNNING on <date & time>

or
Code:
CALLED on <date & time>
RUNNING on <date & time>
SHUTTING_DOWN on <date & time>
DOWN on <date & time>

I don't care about the <date & time> part... I just need to know if the last line in that file starts with 'RUNNING' or 'DOWN' (have to run another script accordingly), how would I do this without Perl?

Thank you!
# 2  
Old 10-24-2006
Code:
tail -1 myfile | grep -q -e '^RUNNING' -e '^DOWN'
if [[ $? -eq 0 ]] ; then # eithe DOWN or RUNNING found
 # run script one
else
  # run script two
fi

# 3  
Old 10-24-2006
Code:
#!/usr/bin/ksh

flg=$(tail -1 file | egrep -ch "^RUNNING|^DOWN")

if [ $flg -ne 0 ]
then
	echo "Call another command here...!!"
fi

# 4  
Old 10-24-2006
Another way using KSH
Code:
if [[ "$(tail -1 inputfile)" = @(RUNNING|DOWN) ]]
then
    echo "Running or Down !"
else
    echo "Other state"
fi


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

Folder contents getting appended as strings while redirecting file contents to a variable

Hi one of the output of the command is as below # sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/' Resource List : <br> *************************** 1. row ***************************<br> ... (2 Replies)
Discussion started by: vivek d r
2 Replies

2. Shell Programming and Scripting

Replace partial contents of file with contents read from other file

Hi, I am facing issue while reading data from a file in UNIX. my requirement is to compare two files and for the text pattern matching in the 1st file, replace the contents in second file by the contents of first file from start to the end and write the contents to thrid file. i am able to... (2 Replies)
Discussion started by: seeki
2 Replies

3. Shell Programming and Scripting

Looking for help with parsing file contents in bash [newbie]

Hi I'm just messing around with bash and trying to learn it because I have a course next semester dealing with OS design where we need to know how to use SSH client and either bash or ksh. I've never done shell scripting before. I just started today and I was wondering how parsing files... (1 Reply)
Discussion started by: mehungry
1 Replies

4. Shell Programming and Scripting

I want to delete the contents of a file which are matching with contents of other file

Hi, I want to delete the contents of a file which are matching with contents of other file in shell scripting. Ex. file1 sheel,sumit,1,2,3,4,5,6,7,8 sumit,rana,2,3,4,5,6,7,8,9 grade,pass,2,3,4,5,6,232,1,1 name,sur,33,1,4,12,3,5,6,8 sheel,pass,2,3,4,5,6,232,1,1 File2... (3 Replies)
Discussion started by: ranasheel2000
3 Replies

5. UNIX for Dummies Questions & Answers

compare 2 file contents , if same delete 2nd file contents

Give shell script....which takes two file names as input and compares the contents, is both are same delete second file's contents..... I try with "diff"...... but confusion how to use "diff" with if ---else Thanking you (5 Replies)
Discussion started by: krishnampkkm
5 Replies

6. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

7. Shell Programming and Scripting

parsing a file and manipulating the contents

Hi I have a text file as follows BOB 14/14 TOM 94/94 SAM 3/3 CRIS 13/13 TOM 6/6 CRIS 27/27 SAM 2/2 JACK 25/25 CRIS (6 Replies)
Discussion started by: shellignorant
6 Replies

8. Shell Programming and Scripting

parsing variable contents with comma delimter

hi, unix gurus. i am trying to read a file that has records in this format... x<group_id>:::<member1a>,<member1b>,<member1c> x<group_id>:::<member2a>,<member2b>,<member2c> ... and to put it in this format: <member1a> <member1b> <member1c> <member2a> <member2b> <member2c> ... (3 Replies)
Discussion started by: ankimo
3 Replies

9. Shell Programming and Scripting

Need help in parsing text file contents

Hi, I need some help in extracting the Exception block between the lines 21 Feb 01:18:54:146 ERROR com.orbits.frameworks.integrationframework.ValidationException - Caught exception in validateRequest() (PID=565584) and 21 Feb 01:18:55:149 INFO ... (0 Replies)
Discussion started by: Alecs
0 Replies

10. Shell Programming and Scripting

Creating file contents using contents of another file

Hi, I am not sure how to start doing this so I hope to get some advice as to how to start. I have 2 files. The source file contains data that I needed is in columns delimited by ";". For example, in this format: "CONTINENT","COUNTRY","CITY","ID" "asia","japan","tokyo","123"... (21 Replies)
Discussion started by: ReV
21 Replies
Login or Register to Ask a Question