Computing.Net > Forums > Unix > script -help

script -help

Reply to Message Icon

Original Message
Name: Devaraj (by Fidy)
Date: February 17, 2006 at 20:36:26 Pacific
Subject: script -help
OS: sun
CPU/Ram: 1280mb
Comment:

Hi,

I need a help. My reqmt is-
say, i have a numeric string of 6 characters long, ie '123456'.
I would like append the numeric string to make a nine character string by inserting zeroes(0) in the begining of the string..ie '000123456'.
In a nutshell, the input and output examples are given below.

Input Output
'123456' ---------> '000123456'
'1234567' --------> '001234567'
'12345678' --------> '012345678'
'123456789'---------> '123456789'

Thanks for your help..

Regards,
Jern


Report Offensive Message For Removal


Response Number 1
Name: FishMonger
Date: February 17, 2006 at 23:47:48 Pacific
Subject: script -help
Reply: (edit)

man sprintf


Report Offensive Follow Up For Removal

Response Number 2
Name: Devaraj (by Fidy)
Date: February 18, 2006 at 07:23:17 Pacific
Subject: script -help
Reply: (edit)

if i do a printf..
say
echo "'"${count}"'"
rowcount=`printf "%13d" $count`
echo "'"${rowcount}"'"

The output is shown as below:

'25290672'
' 25290672'
I would like zeroes inserted there..
like '025290672'.

Regards,
Jern


Report Offensive Follow Up For Removal

Response Number 3
Name: Devaraj (by Fidy)
Date: February 18, 2006 at 07:48:03 Pacific
Subject: script -help
Reply: (edit)

I have got the answer with

rowcount=`printf "%09d" $count`
Thanks to you..

Regards,
Jern


Report Offensive Follow Up For Removal

Response Number 4
Name: WilliamRobertson
Date: February 21, 2006 at 00:09:20 Pacific
Subject: script -help
Reply: (edit)

In ksh, just define the variable as a left-padded integer:

$ typeset -Z9 myvar
$ myvar=123456
$ print $myvar
000123456


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: script -help

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software