Sponsored Content
Top Forums Shell Programming and Scripting bash typeset padding with zeros Post 302212831 by jwheeler on Tuesday 8th of July 2008 12:35:48 PM
Old 07-08-2008
Data bash typeset padding with zeros

Hi everybody,

I have a question about typesetting. I originally wrote a script for use with ksh and now I am on a system that I cannot modify, and it only has bash.

In the original script I just did typeset -RZ4 variable and it would add the leading zeros. In bash, it doesn't work.

I've looked all over and I can't find anything useful that will help me format the variable.

the script is just a simple script to expire about a thousand tapes from netbackup's media database. It's very tedious to do it one at a time with the tapes being labeled NB0000 - NB0999.

so the variable I am typesetting will always be 4 digits.

Any help would be appreciated.

here is the code. it was my first attempt at shell scripting so don't make fun of it too much.

Code:
#! /bin/ksh
# Script to expire tapes in NBU
# REQUIRES that NBU to be installed (DUH)
# Tapes should be in order (ie. NR0000, NR0001, NR0002, etc)

# This ensures that our format will be preserved.
# Makes sure $addon has four digits.
typeset -RZ4 addon

# Get two letter prefix for tapes
clear
echo "Please enter the 2 letter prefix (ie. NR, AB, CD)"
read prefix

# Get the four digits of the first tape
echo "Please enter the last 4 digits of the first tape (ie. 0000 0001 00002)"
read addon

# Get the four digits of the last tape
echo "Please enter the last 4 digits of the last tape to expire"
read last

#Increment the last variable by one so that the while loop will work
let last++

# This creates our tape name (ie NR0000
newfix=$prefix$addon

# While loop to increment through the tapes
while (( $addon <  $last))
do
/usr/openv/netbackup/bin/admincmd/bpexpdate -d 0 -m $newfix -force
let addon++
newfix=$prefix$addon
done
echo " "
echo " "
echo "By the power of Grey Skull, the tapes have expired!"
exit 0


Last edited by rbatte1; 08-03-2017 at 07:11 AM.. Reason: Code tags
 

10 More Discussions You Might Find Interesting

1. HP-UX

Padding zeros after removing commas in file

Hi Gurus, There is a ASCII file in which a comma is used as a seperator for the amount field when the amount exceed seven digits: e.g. 0001300,000. Now, this comma needs to be removed from this field, after padding leading zeros (to maintain the ASCII positions) e.g. 00001300000.... (1 Reply)
Discussion started by: pranag21
1 Replies

2. Shell Programming and Scripting

Help with typeset in bash

Hi everybody, hoping you can help. I'm trying to get some scripts working using bash which were written in ksh and I'm struggling with typeset. Specifically typeset -R and typeset -L. We need fixed length variables with left and right justification and bash does not seem to do it. Spent ages on... (5 Replies)
Discussion started by: Ian_H
5 Replies

3. Shell Programming and Scripting

Help needed in padding leading zeros

Hi all, I have file with numeric values. I need to pad each value with leading zeros such that total lenght of each value is 16. Example: cat tmp.txt 502455 50255 5026 5027 5028 Output 0000000000502455 0000000000050255 0000000000005026 0000000000005027 0000000000005028 Any... (12 Replies)
Discussion started by: jakSun8
12 Replies

4. Shell Programming and Scripting

Padding with zeros.

Hi Friends, I would like to left pad with "0's" on first column say (width six) I have a large file with the format: FILE: 1: ALFRED 84378 NY 8385: JAMES 88385 FL 323: SMITH 00850 TX My output needs to be like: 000001: ALFRED 84378 NY 008385: JAMES 88385 FL 000323: SMITH... (10 Replies)
Discussion started by: sbasetty
10 Replies

5. Shell Programming and Scripting

Typeset conversion problem from ksh to bash

Hi, typeset -l sgf # all lowercase letters typeset -u SGF # all uppercase letters sgf=$1 SGF=$sgf these lines used in my scripts . It ran fine in ksh but when we convert this to bash it erroring out. I like to know what the use of typeset ?? Thanks & Regards kanagaraj (3 Replies)
Discussion started by: kanagaraj
3 Replies

6. Shell Programming and Scripting

bash padding

Hi all Is there a way to pad the output of a bash script see that code below for i in `sed -n '/Start Printer/,/End Printer/p' /u/ab/scripts/hosts.conf | awk '!/^#/ {print $2}' | egrep -v 'broke|primera' `; do pages=`snmpget -Ov -v1 -c public $i sysLocation.0 | awk '{print $2}'` ... (3 Replies)
Discussion started by: ab52
3 Replies

7. Shell Programming and Scripting

zero padding problem (bash)

Hi there, I need to loop some values, for i in $(seq $first $last) do does something here donefor $first and $last, i need it to be of fixed length 5. so if the input is 1, i need to add zeros in front such that it becomes 00001. It loops till 99999 for example, but the length has to be... (4 Replies)
Discussion started by: jremio
4 Replies

8. Shell Programming and Scripting

converting ksh to bash - typeset commands

Hi all, Am trying to convert a script written in ksh to a bash shell. At the moment, am stumped with the typeset -u command and I can't find an equivalent of it in bash. integer function is also not working as is the following if statement if ] && ]; then continue fi Is... (3 Replies)
Discussion started by: newbie_01
3 Replies

9. UNIX for Dummies Questions & Answers

Is there a way to add padding to a bash shell script?

I'm grepping several lines and I want all of them to display with the same padding, is there a command to add whitespace before a line? (1 Reply)
Discussion started by: jcnewton13
1 Replies

10. Shell Programming and Scripting

Sort, sed, and zero padding date column csv bash scripting

Hello people, I am having problem to sort, sed and zero padding of column in csv file. 7th column only. Input of csv file: 1,2,3,4,5,6,4/1/2010 12:00 AM,8 1,2,3,4,5,6,3/11/2010 9:39 AM,8 1,2,3,4,5,6,5/12/2011 3:43 PM,8 1,2,3,4,5,6,12/20/2009 7:23 PM,8 Output:... (5 Replies)
Discussion started by: sean1357
5 Replies
vim-addon-manager(1)					      General Commands Manual					      vim-addon-manager(1)

   ["NAME"]
       vim-addon-manager - command line manager of Vim add-ons

   ["SYNOPSIS"]
       vim-addons [OPTION ...] [COMMAND [ADDON ...]]

   ["DESCRIPTION"]
       Manage Vim addons installed system-wide, enabling on a per-user basis their installation, removal, ...

       vim-addons  is  capable	of  managing  all Vim addons registered in the system-wide registry of Vim addons (see vim-registry(5)). Each sys-
       tem-wide addon can be, with respect to a user Vim configuration, in one of the following states:

       ["installed"]
	      all of the files composing the addon are installed (i.e. symlinked) to their respective places under the target directory. The addon
	      is fully functional for the current user

       ["removed"]
	      the  files  composing the addon are not installed under the target directory.  The addon might still be working for the current user
	      if it is installed system-wide by the local administrator

       ["disabled"]
	      the files composing the addon are not installed under the target directory, but the addon is  installed  system-wide.  However,  the
	      addon has been disabled for the current user explicitly via some configuration line in plugin/vim-addons.vim under the target direc-
	      tory. The addon is not working for the current user

       ["broken"]
	      only some of the files composing the addon are installed under the target directory. The addon is probably not working for the  cur-
	      rent user

       ["unavailable"]
	      some (or all) of the files composing the addon are missing from the source directory

   ["COMMANDS"]
       A  number  of  commands	can  be  given to vim-addons to inspect or alter the status of the addons: list, status, install, remove, disable,
       amend, files, show.

       A description of the semantics of each command is reported below.

       ["list"]
	      list, one per line, the names of the addons available in the system (i.e. of all the addons mentioned in the registry, not necessar-
	      ily of all enabled addons)

       ["status"]
	      show,  one  per  line,  the status of the addons available in the system. If one or more addon arguments are specified only show the
	      status of those addons.  This is the default command if nothing is specified.

       ["install"]
	      install one or more addons under the target directory. Requires at least one addon argument

       ["remove"]
	      remove one or more addons from the target directory. Requires at least one addon argument

       ["disable"]
	      disable one or more addons to be used by the current user. Usually used for addons which are system-wide enabled by the local admin-
	      istrator	but  that  the	current  user  does not want to be used. Using this command will automatically change the content of plug-
	      in/vim-addons.vim under the target directory, probably adding ":let" commands which will inhibit the given addon	from  being  used.
	      Requires at least one addon argument

       ["enable"]
	      undo the effects of a previous disable command. Requires at least one addon argument

       ["files"]
	      list,  one  per  line, the files composing the specified addons. Files are listed relative to components of the Vim runtimepath (see
	      'runtimepath' in the Vim help). Requires at least one addon argument

       ["show"]
	      displays detailed information about the specified addons

   ["OPTIONS"]
       All commands accept the following options:

       ["-h, --help"]
	      show this usage message and exit

       ["-q, --query"]
	      be quiet and make the output more parseable (for "status")

       ["-r, --registry-dir"]
	      set the registry directory (default: /usr/share/vim/registry)

       ["-s, --source-dir"]
	      set the addons source directory (default: /usr/share/vim/addons)

       ["-t, --target-dir"]
	      set the addons target directory (default: $HOME/.vim)

       ["-v, --verbose"]
	      increase verbosity level

       ["-z, --silent"]
	      silent mode: supress most of the output

       ["-y, --system-dir"]
	      set the system-wide target directory (default: /var/lib/vim/addons)

       ["-w, --system-wide"]
	      set the addons target directory to the system-wide target directory, possibly overriding the -t option

   ["AUTHOR"]
       Stefano Zacchiroli <zack@debian.org> James Vega <jamessan@debian.org>

   ["SEE ALSO"]
       vim(1), vim-registry(5)

   ["COPYRIGHT"]
       Copyright (C) 2007 Stefano Zacchiroli Copyright (C) 2009 James Vega

       This program is free software, you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as pub-
       lished by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

								   October 2012 					      vim-addon-manager(1)
All times are GMT -4. The time now is 02:19 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy