Reduce


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reduce
# 1  
Old 12-01-2008
Reduce

Code:
printf "\nClosing stats:\n" >> data.txt
        echo >> data.txt               
sed 's/^ \t*//;/^#/d;/^$/d' $stats | while read line   
do
    close=$(grep -w "^$line" $datafile | sed -e 's/\(.*\),\(.*\),\(.*\)/\2/')   
    if [ "$close" == "" ]; then   
        printf "%5d. %-s was not found in file\n" $counter $line 
    else
        printf "%5d. %-7s  : $  %6.2f\n" $counter $line $close   
    fi
    counter=$(( counter + 1 ))   
done >> data.txt
        echo >> data.txt
        usrname -srvio | awk '{print $1, $2, $3, $4, $11, $12}' >> data.txt 
        echo "Last Updated "$time >> data.txt 
}

i have this portion of my script that i need help reducing
i tired several methods but it ended up the same length
# 2  
Old 12-01-2008
Got rid of the echo command after the first printf and added another '\n' to the first printf. Otherwise, this is challenging to do w/o seeing the data going into the line variable.


Code:
printf "\nClosing stats:\n\n" >> data.txt
                      
sed 's/^ \t*//;/^#/d;/^$/d' $stats | while read line   
do
    close=$(grep -w "^$line" $datafile | sed -e 's/\(.*\),\(.*\),\(.*\)/\2/')   
    if [ "$close" == "" ]; then   
        printf "%5d. %-s was not found in file\n" $counter $line 
    else
        printf "%5d. %-7s  : $  %6.2f\n" $counter $line $close   
    fi
    counter=$(( counter + 1 ))   
done >> data.txt
        echo >> data.txt
        usrname -srvio | awk '{print $1, $2, $3, $4, $11, $12}' >> data.txt 
        echo "Last Updated "$time >> data.txt 
}

# 3  
Old 12-01-2008
Hi,

Code:
close=$(grep -w "^$line" $datafile | sed -e 's/\(.*\),\(.*\),\(.*\)/\2/')

can be reduced to:

Code:
close=$(sed -n "/\<${line}\>/{s/\(.*\),\(.*\),\(.*\)/\2/")} $datafile)

Which will save you the calling of one external process in each loop.

HTH Chris
# 4  
Old 12-01-2008
You didn't mention your shell.

Code:
if [ "$close" == "" ]; then

replace by:
Code:
if [ -z "$close" ]; then

Code:
echo >> data.txt
usrname -srvio | awk '{print $1, $2, $3, $4, $11, $12}' >> data.txt

replace by:
Code:
usrname -srvio | awk '{print;print $1, $2, $3, $4, $11, $12}' >> data.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reduce redundant file

Dear All, I have to reduce the redundancy of a file that is like this: a b 0 a c 0 a f 1 b a 1 b a 0 b c 1 d f 0 g h 1 f d 1 Basically, this file describe a network with relative nodes and edges. The nodes are the different letters and the edges are represented by the numbers (in... (7 Replies)
Discussion started by: giuliangiuseppe
7 Replies

2. Shell Programming and Scripting

Help to reduce time of archiving

hi all, i have written the following script that does this work: 1. copy large logs files from one server to another. 2. then unzip this files and extraxt from these large https logs only those fields that are neccesary. 3. then archive the extracted logs to new files. BUT the problem is... (7 Replies)
Discussion started by: arrals_vl
7 Replies

3. Shell Programming and Scripting

How to reduce code.....

Hi All, Could some one help me to reduce the code... if then ./plist -m "$queuename" |grep $2|awk '{print $3}' >unlock.log elif then ./plist -m "$queuename" |grep $2|awk '{print $4}' >unlock.log else ./plist -m "$queuename" |grep $2|awk '{print $5}' >unlock.log . . . . ... (1 Reply)
Discussion started by: harshakusam
1 Replies

4. Shell Programming and Scripting

how to reduce a length in a file?

i want to reduce a length in the file called text in the file im having 10 byte length. want to reduce it to 9 byte length for all lines. (5 Replies)
Discussion started by: laknar
5 Replies

5. AIX

reduce used paging space

Hi I have used gzip on AIX and the used paging space has jumped from 7% to 20%. The gzip process is finished since a long time. But the used paging space is still the same. How to release this space ? (1 Reply)
Discussion started by: bfarah
1 Replies

6. Shell Programming and Scripting

reduce a string

hi i have a string "hostname=lpdma520_dev_ipc_us_aexp_com" now i need only "newHostname=lpdma520" how to do this one please help soon (2 Replies)
Discussion started by: satish@123
2 Replies

7. Shell Programming and Scripting

To reduce execution time

Hi All, The below script I run daily and it consumes 2 hours approx. In this I am calling another script and executing the same twice. Is the loop below the cause for the slow process?Is it possible to finetune the program so that it runs in a much faster way? The first script: #!/bin/ksh... (4 Replies)
Discussion started by: Sreejith_VK
4 Replies

8. UNIX for Dummies Questions & Answers

Can I reduce sysdump?

Hi, I have a server which is running out of space on the rootvg. When trying to find some spare space I discovered there are 2 sysdump logical volumes, each of 5GB, yet if I get an estimate of the dump size it's only 0.5 GB. $ lsvg -l rootvg|grep sysdump hd71 sysdump 20 ... (1 Reply)
Discussion started by: m223464
1 Replies

9. Shell Programming and Scripting

reduce the or conditions

Hi , how can i reduce the or conditions: if ]; then whatever fi (8 Replies)
Discussion started by: hitmansilentass
8 Replies

10. AIX

reduce available ram

hello, we have a aix 5.2 server with 8GB of ram. is it possible, without actually removing the hardware, to have the O/S think it has only 4GB of ram? We would like to see how the handles and responds if it only had 4Gb instead of the 8GB. Any ideas or suggestions? Thanks Looks like i found... (6 Replies)
Discussion started by: zuessh
6 Replies
Login or Register to Ask a Question