Shell Script to Search for a particular String and copy the timestamp to a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script to Search for a particular String and copy the timestamp to a variable
# 1  
Old 09-02-2010
Error Shell Script to Search for a particular String and copy the timestamp to a variable

Hi,
We Perfrom Loads to the database through a Perl script which generates a statistics file. I need to read the statistics. the Statistics file looks something like below:

Code:
Process Beginning - 08-26-2010-23.41.47
DB2 CONNECTION SUCCESSFUL!
Ready to process and load file:  FILENAME
# of rows in the TABLENAME table before inserts was 8364
FILENAME - RECORDS READ COUNT:  4838
FILENAME - INSERTED ROW COUNT:  129
FILENAME - ERROR RECORDS COUNT:  0
# of rows in the audit.ELIG_RESP_AUDIT  table after inserts was 8493
Process Complete 08-26-2010-23.41.49

There are many instance like the above in a single file.I am able to open the file and read line by line. But, my requirement is to read the Process Beginning, INSERTED ROW COUNT: and Process Complete into three variables. The count should keep on adding between a process.

can anyone please help me with this?

Last edited by Praveenkulkarni; 09-02-2010 at 02:48 PM.. Reason: Code tags, please!
# 2  
Old 09-02-2010
Try something like...
Code:
$ cat file1
Process Beginning - 08-26-2010-23.41.47
DB2 CONNECTION SUCCESSFUL!
Ready to process and load file:  FILENAME
# of rows in the TABLENAME table before inserts was 8364
FILENAME - RECORDS READ COUNT:  4838
FILENAME - INSERTED ROW COUNT:  129
FILENAME - ERROR RECORDS COUNT:  0
# of rows in the audit.ELIG_RESP_AUDIT  table after inserts was 8493
Process Complete 08-26-2010-23.41.49

$ eval $(awk '/Process Beginning/  { print $2 "[" ++c "]=" $NF }
            /INSERTED ROW COUNT/ { i+= $NF ; print "Inserted[" c "]=" i }
            /Process Complete/   { print $2 "[" c "]=" $NF }' file1)

$ echo ${Beginning[1]} ${Inserted[1]} ${Complete[1]}
08-26-2010-23.41.47 129 08-26-2010-23.41.49

$

# 3  
Old 09-03-2010
So guess every instance has only one Process Beginning, INSERTED ROW COUNT and Process Complete .
Code:
awk '
/Process Beginning/ { printf  $NF " "}
/INSERTED ROW COUNT/ { printf $6 " "}
/Process Complete/   { printf $NF "\n"}
' statistics.file |while read LINE
do
   # add the jobs here
done.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to Search a string in a file in shell script?

I have a text file which is generated when the batch job is run. This batch may take few mins to run. When completed, the last line of the text file would be process completed. I need a shell script which will wait for this file till the process completed is printed in it, once found, it would move... (2 Replies)
Discussion started by: Lalat
2 Replies

2. Shell Programming and Scripting

Linux shell script, search by an input string

So, there is a large file where I have to conduct several search using bash shell scripting. The file is like this: TITLE and AUTHOR ETEXT NO. Aspects of plant life; with special reference to the British flora, 56900 by Robert Lloyd... (1 Reply)
Discussion started by: Philia
1 Replies

3. Shell Programming and Scripting

Shell script to search all files for every string in another file

Hello All I have a pattern.txt file in source directory ((/project/source/) in linux server and data looks like: 123abc17 234cdf19 235ifg20 I have multiple log files in log directory (/project/log/) in linux server and data for one log file looks like: <?xml version="1.0" processid... (11 Replies)
Discussion started by: pred55
11 Replies

4. Shell Programming and Scripting

UNIX shell script to search a string in a file

Hi folks, I am new for shell script, I hope somebody to help me to write shell script My requirement is below steps 1. I have apache access.log i.e located in /var/log/httpd/ Ex. 127.0.0.1 - - "GET... (14 Replies)
Discussion started by: Chenchireddy
14 Replies

5. UNIX for Dummies Questions & Answers

Comparing a String variable with a string literal in a Debian shell script

Hi All, I am trying to to compare a string variable with a string literal inside a loop but keep getting the ./testifstructure.sh: line 6: #!/bin/sh BOOK_LIST="BOOK1 BOOK2" for BOOK in ${BOOK_LIST} do if then echo '1' else echo '2' fi done Please use next... (1 Reply)
Discussion started by: daveu7
1 Replies

6. Shell Programming and Scripting

shell script to search and copy files

Hello Im new to this forums, I would like some help regarding a script that I need in order to copy some files. Heres the scenario: I need to search several files which have a particular code inside, lets say "test" all of them on different directories. I need to copy all of them on a new... (4 Replies)
Discussion started by: c.watson
4 Replies

7. UNIX for Dummies Questions & Answers

Search for a string and copy the entire line

Hello All, I am after the script or the command which can scan the entire file for a string $PART_ID and when found to extract/copy the corresponding $PART_ID value (e.g THIRE_PTY_SOFTWARE for the 1st occurance of $PART_ID in the attached file) to a file. Appreciate your help. Thanks in... (3 Replies)
Discussion started by: forumthreads
3 Replies

8. Shell Programming and Scripting

Search for string in a file and extract another string to a variable

Hi, guys. I have one question: I need to search for a string in a file, and then extract another string from the file and assign it to a variable. For example: the contents of the file (group) is below: ... ftp:x:23: mail:x:34 ... testing:x:2001 sales:x:2002 development:x:2003 ...... (6 Replies)
Discussion started by: daikeyang
6 Replies

9. UNIX for Dummies Questions & Answers

Shell script to search for text in a file and copy file

Compete noob question.... I need a script to search through a directory and find files containing text string abcde1234 for example and then copy that file with that text string to another directory help please :eek: (9 Replies)
Discussion started by: imeadows
9 Replies

10. Shell Programming and Scripting

shell script to search a string and delete the content

Hi, I've a shell script e.g. #!/bin/bash echo "Enter the next hop id" read nhid echo "enter the IP address" read IP echo "enter the interface name" read name echo "enter the enable/disable state" read state exit 0 now from this script i want to search strings in another (.cam) ... (6 Replies)
Discussion started by: vic_mnnit
6 Replies
Login or Register to Ask a Question