Sponsored Content
Top Forums Shell Programming and Scripting Help me streamline this counting part of my script. Post 302170715 by joeyg on Tuesday 26th of February 2008 02:13:37 PM
Old 02-26-2008
Hammer & Screwdriver A different approach (actually, two!)

Here is the new script

Code:
> cat alpha1
#! /bin/bash

#remove old files
rm count.txt 2>/dev/null
rm p1vma* 2>/dev/null

#set the variable
NUMBER=13
CURRENT=0
while [ $CURRENT -le $NUMBER ]
   do
      if [ $CURRENT -gt 1 ]
         then
#         printf "%.2d \n" $CURRENT
         printf "%.2d \n" $CURRENT >>count.txt
         lv_val=$(printf "%.2d" $CURRENT)
#do lv stuff here
         touch p1vma$lv_val
      fi
      CURRENT=$(($CURRENT + 1))
done

#see the files just created
ls -l p1vma*

It creates the count.txt file, although not sure if truly needed...
Code:
> cat count.txt
02 
03 
04 
05 
06 
07 
08 
09 
10 
11 
12 
13

because, you can do you lv stuff while inside the loop. In this case, I touch'ed files to create/put timestamp. See the following as output from execution

Code:
> alpha1
-rw-rw---- 1 jgillis dp 0 Feb 26 11:08 p1vma02
-rw-rw---- 1 jgillis dp 0 Feb 26 11:08 p1vma03
-rw-rw---- 1 jgillis dp 0 Feb 26 11:08 p1vma04
-rw-rw---- 1 jgillis dp 0 Feb 26 11:08 p1vma05
-rw-rw---- 1 jgillis dp 0 Feb 26 11:08 p1vma06
-rw-rw---- 1 jgillis dp 0 Feb 26 11:08 p1vma07
-rw-rw---- 1 jgillis dp 0 Feb 26 11:08 p1vma08
-rw-rw---- 1 jgillis dp 0 Feb 26 11:08 p1vma09
-rw-rw---- 1 jgillis dp 0 Feb 26 11:08 p1vma10
-rw-rw---- 1 jgillis dp 0 Feb 26 11:08 p1vma11
-rw-rw---- 1 jgillis dp 0 Feb 26 11:08 p1vma12
-rw-rw---- 1 jgillis dp 0 Feb 26 11:08 p1vma13

 

2 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

counting in shell script

hi i am writing a korn shell script to compile all programs there are arount 2000+ files now i have a script that can compile programs but i want to show status of compilation because to compile all programs it takes around 10-15 mins so how can i display status like it should print no of files... (3 Replies)
Discussion started by: zedex
3 Replies

2. Shell Programming and Scripting

Streamline script to search for numbers in a certain range

Hello all, I need help making a script run faster since I have a huge file to sift through. The file I am running my script on looks like this: 1 -1.9E+001 -1.8E-001 1.5E+001 3.32E+001 2 -1.7E+001 -1.0E-002 1.2E+001 6.37E+001 3 -1.5E+001 -3.8E-006 6.7E+001 4.81E+001 The... (12 Replies)
Discussion started by: butson
12 Replies
lastcomm(8)						      System Manager's Manual						       lastcomm(8)

NAME
lastcomm - Outputs information about the last commands executed SYNOPSIS
lastcomm [Command] [Name] [Tty] DESCRIPTION
The lastcomm command outputs information about all previously executed commands that are recorded in the /var/adm/pacct file in reverse chronological order. You may specify a particular command with the Command parameter, a particular user with the Name parameter, and a particular terminal as the command source with the Tty parameter. Output is then restricted to the specified parameters. A Tty terminal may be named fully (for example, tty0) or abbreviated (for example, 0). The following information is displayed for each process: Name of the command under which the process was called. Any flags collected when the command was executed. The following flags are valid: Command was run with an effective user-id of 0. Command ran after a fork, but without an exec system call following it. Name of the user who issued the command. The terminal the command was started from. Seconds of CPU time used. Time the process started. EXAMPLES
To display information about all previously executed commands recorded in the /var/adm/pacct file, enter: lastcomm Information is displayed similar to: lastcomm ajh lat/620 1.13 secs Thu Feb 24 15:02 pg ajh lat/620 5.91 secs Thu Feb 24 15:01 ln miller ttyp1 1.14 secs Thu Feb 24 15:01 ls rob ttyp1 0.02 secs Thu Feb 24 15:01 pg sjz ttyp1 0.33 secs Thu Feb 24 15:00 sendmail SF root __ 0.01 secs Thu Feb 24 15:00 To display information about commands named a.out executed by the root user on terminal ttyd0, enter: lastcomm a.out root ttyd0 FILES
Specifies the command path. The current accounting file. RELATED INFORMATION
Commands: last(8) delim off lastcomm(8)
All times are GMT -4. The time now is 12:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy