![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| To Write a Shell script that takes two arguments. | bobby36 | Shell Programming and Scripting | 3 | 04-05-2007 08:44 PM |
| why shell scripting takes more time to read a file | brkavi_in | Shell Programming and Scripting | 1 | 06-23-2006 08:20 AM |
| Killing a process that takes too long | WeezelDs | Shell Programming and Scripting | 3 | 04-10-2006 03:33 PM |
| fwrite takes extremely long time | inna | High Level Programming | 5 | 07-06-2005 06:19 AM |
| Finding out how long a command takes to run | cfoxwell | UNIX for Dummies Questions & Answers | 3 | 11-22-2001 01:50 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Hi all,
I wrote this shell script to validate filed numbers for input file. But it take forever to complete validation on a file. The average speed is like 9mins/MB. Can anyone tell me how to improve the performance of a shell script? Thanks |
|
||||
|
matrixmadhan,
I don't have the script right here with me, but I can brief you how my script looks like. Code:
#starts with couple of constants for the file
function1 ...
function2 ...
function3
{
function4
}
function4...
while time < 00:00:00
do
function1
if [ $? -eq 0 ]
then
for loop
do
function2...
function4...
./call_another_script
done
fi
done
|
|
||||
|
Thanks for the reply
the part that take the most of the time is the following code.
Code:
function line_count
{
COUNT=`echo $1 | awk -F\| '{print NF}'`
if [ "$COUNT" != "$2" ]
then
error_log "File $FN: Validation failed at line $LINENUM. Expected $2, getting $COUNT"
return 5
fi
}
function validate_line
{
if [ "$1" = "$FIRST_LEVEL_HEAD" ]
then
line_count "$2" $FIRST_LEVEL_COUNT
return $?
elif [ "$1" = "$SECOND_LEVEL_HEAD" ]
then
line_count "$2" $SECOND_LEVEL_COUNT
return $?
else
error_log "File $FN: Line $LINENUM head is not regconised"
return 5
fi
}
function validate_file
{
trace_log "Start to validate $FN..."
LINENUM=0
ERROR=0
while read LINE
do
LINENUM=`expr $LINENUM + 1`
LINE_HEAD=`echo $LINE | awk -F\| '{print $1}'`
validate_line $LINE_HEAD "$LINE"
if [ ! $? -eq 0 ]
then
ERROR=1
fi
done < $1
if [ ! $ERROR -eq 0 ]
then
return 7
fi
}
validate_file $FILE
Any suggestion ? |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| grep or |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|