Sponsored Content
Top Forums Shell Programming and Scripting Optimized way of doing the task in shell programming Post 302196036 by pcjandyala on Friday 16th of May 2008 02:28:19 PM
Old 05-16-2008
Optimized way of doing the task in shell programming

Hi

I have a file consists of the following similar lines (10 mb file)

2008-05-15 02:15:38,268 [DEBUG] [AQUEDUCT-WebContainer : 3] RMSConnectionFactory - Setting session state for connection.

2008-05-15 02:15:38,277 [DEBUG] [AQUEDUCT-WebContainer : 3] RMSConnectionFactory - Returning WS connection.

My task is to find out any missing second lines for corresponding first lines.

I have written a script using bash, perl and awk commands but it takes lot of time to complete it. is there a better way to do this task ?

here is my current script:
=====
#FILE contains a list of connection and return statements
FILE=summary_db_conn.txt
#DUP_FILE : Copying as another file so that i can do a loop to find out the missing return statements
DUP_FILE=summary_db_conn_dup.txt
#FINAL_FILE = file contains setting session records which don't have corresponding return statements
FINAL_FILE=final_not_matching_records.txt


# To see whether set connection statements have corresponding return connection statements

while read line; do

temp_output=`echo $line | grep "Setting session state for connection" | awk '{ print $1, $2, $4, $5, $6, $7 }' | perl -wn -e 'print "$1\n" if m{[\[](.*?)[\]]};'`
if [ "$temp_output" != "" ]; then
echo "$line :Processing line "
get_time=`echo $line | grep "Setting session state for connection" | awk '{ print $1,$2 }'`
#echo "get_time $get_time"
flag="0"
while read file_line; do
#echo "Match line : $file_line"

if [ "$flag" = "1" ]; then
temp_file_output1=`echo $file_line | grep "Returning WS connection" | awk '{ print $1, $2, $4, $5, $6, $7 }' | perl -wn -e 'print "$1\n" if m{[\[](.*?)[\]]};'`
if [ "$temp_file_output1" != "" ]; then
if [ "$temp_output" = "$temp_file_output1" ]; then
# echo "Found the matching return statement"
echo "$file_line"
echo "Break: Success"
break
fi
else
temp_file_output1=`echo $file_line | grep "Setting session state for connection" | awk '{ print $1, $2, $4, $5, $6, $7 }' | perl -wn -e 'print "$1\n" if m{[\[](.*?)[\]]};'`
if [ "$temp_file_output1" != "" ]; then
if [ "$temp_output" = "$temp_file_output1" ]; then
echo $line >> $FINAL_FILE
#echo "Searching for:$line"
echo "Sorry found another session start statement with the same thread $line"
echo "The new Line is:$file_line"
break
fi
fi
fi
fi
temp_file_output=`echo $file_line | grep "$get_time"`

if [ "$temp_file_output" != "" ]; then
#echo "Found line"
#echo "$file_line"
flag="1"
fi

done < $DUP_FILE
fi

done < $FILE

echo "Program Ended`date`" >> $FINAL_FILE
====

Please let me know is there a fast and better way of doing this task ....


Thanks
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

searchin optimized

hi friens, :) if ther are files named .c++,.C++,.cpp,.Cpp,.CPp,.cPP,.CpP,.cpP,.c,.C wat is the pattern for finding them :confused: (1 Reply)
Discussion started by: arunsubbhian
1 Replies

2. Shell Programming and Scripting

comment and Uncomment single task out of multiple task

I have a file contains TASK gsnmpproxy { CommandLine = $SMCHOME/bin/gsnmpProxy.exe } TASK gsnmpdbgui { CommandLine = $SMCHOME/bin/gsnmpdbgui.exe I would like to comment and than uncomment specific task eg TASK gsnmpproxy Pls suggest how to do in shell script (9 Replies)
Discussion started by: madhusmita
9 Replies

3. Shell Programming and Scripting

Parse an XML task list to create each task.xml file

I have an task definition listing xml file that contains a list of tasks such as <TASKLIST <TASK definition="Completion date" id="Taskname1" Some other <CODE name="Code12" <Parameter pname="Dog" input="5.6" units="feet" etc /Parameter> <Parameter... (3 Replies)
Discussion started by: MissI
3 Replies

4. Shell Programming and Scripting

Shell scripting task

Hi all, I am new to shell scripting. And I have a task to do, I tried all possible ways to solve this, but didn't. Iwas wondering maybe someone could help me. So I have a random file something like this Andrew John Mike Alfa Omega Beta And I need to create scrip witch would filter any... (1 Reply)
Discussion started by: Strongid
1 Replies

5. Homework & Coursework Questions

Shell scripting task

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Hi all, I am new to shell scripting. And I have a task to do, I tried all possible ways to solve this, but... (8 Replies)
Discussion started by: Strongid
8 Replies

6. Shell Programming and Scripting

Can any programmer do this task in shell script...

input file's one set header is this, ----------------------------------------------------- OUTPUT FROM ASCII FILE: CAST #1 ----------------------------------------------------- CC Cruise Latitude Longitude YYYY MM DD Time Cast #Levels CA 8504 50.083 -144.883 1970 1 2... (6 Replies)
Discussion started by: Akshay Hegde
6 Replies

7. Shell Programming and Scripting

Whether Shell script can do this task ???

In following attached 748phy.xls file, fifth column is ST_Date, which contains time and dates in this format 22-11-2012 7:54:54 PM in single column I want it to split in this format either 1st column 22/11/2012 and in second column 7:54:54 PM Or like this in separate... (13 Replies)
Discussion started by: Akshay Hegde
13 Replies

8. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

9. UNIX for Beginners Questions & Answers

Need list of input and output parameter of task in a text file, using shell script

//file begin ===== //some code task abcd_; input x; input y,z; //some comment output w; //some comment reg p; integer q; begin //some code end endtask : abcd_ //some code //file end ===== expected output from above... (1 Reply)
Discussion started by: rishifrnds
1 Replies

10. UNIX for Advanced & Expert Users

Need optimized awk/perl/shell to give the statistics for the Large delimited file

I have a file size is around 24 G with 14 columns, delimiter with "|" My requirement- can anyone provide me the fastest and best to get the below results Number of records of the file First column and second Column- Unique counts Thanks for your time Karti ------ Post updated at... (3 Replies)
Discussion started by: kartikirans
3 Replies
All times are GMT -4. The time now is 10:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy