loop alternative?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting loop alternative?
# 1  
Old 04-30-2002
loop alternative?

I have a 1-column file with
random numbers. this script runs
to subtract 1 to the number and
written to a file. With over
10,000 lines, it takes >2 minutes
to complete the loop operation.

is there an alternative awk/sed
for looping to reduce the wait?
Thanks!

#!/bin/ksh
for N in `cat oldfile`
do
echo `expr $N- 1` >> newfile
done
# 2  
Old 04-30-2002
Try this:

Code:
#! /usr/bin/ksh
exec < inputfile > outputfile
while read n ; do
       ((n=n-1))
       print $n
done
exit 0

# 3  
Old 05-02-2002
worked great!! thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Please help -- any alternative to expect ?

Doing some automation to automate some server tasks in Linux through shell scripting. In the script I tried to call a expect script to log into another server and execute a command. Please note: passwordless SSH is not possible hence am trying some User-interactive commands like Expect to send... (2 Replies)
Discussion started by: alldbest
2 Replies

2. Shell Programming and Scripting

Alternative to Sleep?

Greetings. I've been wondering about this one for some time: Is there an alternative to sleep in bash? The reason: I'd like to simply limit the amount of processor usage in continuous while : script scenarios without spawning endless sleep processes as well. After beating the manpages, I... (14 Replies)
Discussion started by: LinQ
14 Replies

3. Shell Programming and Scripting

Looking for an alternative to Tcl

I've created quite a collection of tcl scripts which have buttons, radio buttons, check boxes, text fields, etc. These tcl scripts in turn call and execute several hundred sh, csh, bash, perl scripts and pass in the args based on the gui selections on the same and other redhat machines. We're... (4 Replies)
Discussion started by: scottwevans
4 Replies

4. Shell Programming and Scripting

Alternative to the loop is needed

I have a file containing ids like this (file1): c9e2c3c6c100000000460000c02000803c63e529c3f5f5f0 c9e2c3c6c100000000460000c02002813c63e539c3f5f5f0 c9e2c3c6c100000000460000c02002ee3c63ebb1c3f5f5f4 c9e2c3c6c100000000460000c020042f3c63e549c3f5f5f0 These ids are present in muiltiple files named:... (4 Replies)
Discussion started by: niladri29
4 Replies

5. Solaris

vi alternative

Is there any other editor, installed by 'default' in Sparc Solaris10, besides vi? I'd like to avoid installing anything new. If not, how to make vi more user-friendly? thanks. (8 Replies)
Discussion started by: orange47
8 Replies

6. Shell Programming and Scripting

Alternative for wc -l

Hi techies .. This is my first posting hr .. Am facing a serious performance problem in counting the number of lines in the file. The input files i get will be in some 10 to 15 Gb of size or even sometimes more ..and I will load it to db I have used wc -l to confirm whether the loader... (14 Replies)
Discussion started by: rajesh_2383
14 Replies

7. Shell Programming and Scripting

Alternative for Cron

Hi... I want to know whether if there is any alternative for cron.:confused: I had written a script which checks for all system/application processes every 15 min(placed in cron though). But looks funny - what if cron daemon isn't running!! and expecting that script to update the OUTPUT FILE... (5 Replies)
Discussion started by: reddybs
5 Replies

8. Shell Programming and Scripting

help with while loop or any other alternative?

i=1 while do mm=02 dd=03 yy=2008 echo "$mm$dd$yy" i=$(( i+1)) echo "$i" done whenever i execute the script above i will get the error below: syntax error at line 30: `i=$' unexpected (3 Replies)
Discussion started by: filthymonk
3 Replies

9. Shell Programming and Scripting

getopts alternative?

I have to implement switches (options) like this in my script. ./myscript -help ./myscript -dir /home/krish -all ./myscript -all getopts allows switches to have one character (like a, b, etc.). How can I customize it for handling the above situation? Or, is there any alternative to... (3 Replies)
Discussion started by: krishmaths
3 Replies

10. UNIX for Dummies Questions & Answers

Alternative for a while read line loop

HELLO all :), I have been trying to use a simple while loop to read a file " templist", line by line and perform an action. See the code below. The reason for not using a while read line loop is the for the use of the if condition that wouldn't work. I would appreciate some ideas as this has... (2 Replies)
Discussion started by: kabs
2 Replies
Login or Register to Ask a Question