Computing.Net > Forums > Unix > script -help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

script -help

Reply to Message Icon

Name: Devaraj (by Fidy)
Date: February 17, 2006 at 20:36:26 Pacific
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



Sponsored Link
Ads by Google

Response Number 1
Name: FishMonger
Date: February 17, 2006 at 23:47:48 Pacific
Reply:

man sprintf


0

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

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


0

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

I have got the answer with

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

Regards,
Jern


0

Response Number 4
Name: WilliamRobertson
Date: February 21, 2006 at 00:09:20 Pacific
Reply:

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

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


cut file for non-eng char... Tkdiff is too slow



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: script -help

Unix script help www.computing.net/answers/unix/unix-script-help/6110.html

Korn script help!! www.computing.net/answers/unix/korn-script-help/4858.html

Shell Scripting Help www.computing.net/answers/unix/shell-scripting-help/5020.html