The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
Adding a columnfrom a specifit line number to a specific line number Ezy Shell Programming and Scripting 2 05-12-2008 09:29 AM
Appending line number to each line and getting total number of lines chiru_h Shell Programming and Scripting 2 03-25-2008 10:19 AM
Number count per number ranges shirleyeow Shell Programming and Scripting 5 12-19-2007 04:06 AM
to print number one less than actual number cdfd123 Shell Programming and Scripting 4 09-06-2007 07:56 AM
number pad in vi c19h28O2 SUN Solaris 5 09-21-2006 03:41 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-03-2002
thangorn
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
Smile Increminting a number

Hi

im creating lots of log files, Im writing a script to number them and scp them to a remote server,
the files need to be called 0001.log 0002.log etc etc

in my script I made a counter variable

$counter=00001

I tried adding a number to the variable like this
$counter=`echo "$counter + 1" | bc`

but this gives me 2 not 0002

i tried with perl also $counter++


does anyone know a simple way to imrement but keep the leding 0's ??

Thanks
  #2 (permalink)  
Old 01-03-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,127
Try this:
Code:
#! /usr/bin/ksh
typeset -Z4 number=0
while ((number<10)); do
    ((number=number+1))
    echo $number
done
exit 0

  #3 (permalink)  
Old 01-03-2002
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
I keep a list of all RFC's on my workstation for some idle reading, and use a script to diplay a topic for the number I supply. The format they're in is: rfc####.txt, where the extra spaces are padded by "0"'s. I came up with this simple little routine to pad the left side of the number with zero's until I get a total of 4 characters:

Code:
...
numcheck=$((`echo $num | wc -c` - 1))
until [ "$numcheck" = "4" ]; do
num="0${num}"
numcheck=$((`echo $num | wc -c` - 1))
done
rcfname=rfc${num}.txt
...

This may not be the best way to do it, but it works for my needs... Please post back if you want more help with this.

HTH
  #4 (permalink)  
Old 01-03-2002
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Wow, I like Perderabo's much better.... time to re-write rfc.sh!
  #5 (permalink)  
Old 01-03-2002
thangorn
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
Talking

Thanks guys, my script works fine now

its was this command that I needed form your script

typeset -Z4 number=0





  #6 (permalink)  
Old 01-03-2002
Cameron's Avatar
Cameron Cameron is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2001
Location: Brisbane, Australia
Posts: 500
Livinfree, What exactly do you refer to as RFC's ??

Silly newbie question I guess
  #7 (permalink)  
Old 01-03-2002
thangorn
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
request for comment

I presume he means.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:14 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0