Addition with the prefixing zeros included


View Poll Results: Do you find this post helpful
Not helpful 0 0%
Very Helpful 0 0%
Voters: 0. This poll is closed

 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Addition with the prefixing zeros included
# 15  
Old 09-30-2006
To Anbu23,

It worked.
Thanks for your reply and my apology for being a dumb.

To mph,
Simple way using awk:
Code:
read x
echo $x | awk '{ printf "%0"length"d\n", ++$0 }'

Cheers,
Tayyab

Last edited by tayyabq8; 09-30-2006 at 04:29 AM..
# 16  
Old 09-30-2006
Quote:
Originally Posted by sivasenthil_k
Hi

I need to do an add function but it should include the prefixed zeros

For Example
i=00123
j=`expr $i + 1`

The output it shows is 124 but I want the output to be 00124

Could any one help me finding out how to do this

Thanks
Its easy with Python

Code:
import string
i = "00123"
print string.zfill( int(i) + 1 , len(i) )

Output:
Code:
00124

# 17  
Old 09-30-2006
shereenmotor,
Quote:
To mph,
Simple way using awk:
Code:
read x
echo $x | awk '{ printf "%0"length"d\n", ++$0 }'

Cheers,
Tayyab
Sweeeet! I'm all for less code, but my two remaining brain cells are for less thinking. So I'll have to commit this on to my favorite code snippets file. Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Date included

#!/usr/bin/ksh # This script reads the *.rpt files created by xenos during job execution. # The job name, jobid, number of pages processed and pdf files created for each job # are added to the xenoshistory.txt file Currently the ouput file looks like this but I need a date where the... (3 Replies)
Discussion started by: bcarosi
3 Replies

2. Shell Programming and Scripting

Rm -rf file.txt~ included in the first step?

I need to shred and delete a file after a certain time. Therefore I use shred -z /path/to/file.txt | rm -rf /path/to/file.txtIt works well, but typing in that very directory ls -shiI still see the so called backup-copy lets say file.txt~ When running bleachbit it will disappear thoroughly.... (3 Replies)
Discussion started by: 1in10
3 Replies

3. Shell Programming and Scripting

Prefixing test case methods with letter 'test'

Hi, I have a Python unit test cases source code file which contains more than a hundred test case methods. In that, some of the test case methods already have prefix 'test' where as some of them do not have. Now, I need to add the string 'test' (case-sensitive) as a prefix to those of the... (5 Replies)
Discussion started by: royalibrahim
5 Replies

4. Solaris

What update level included fcinfo?

Hi all first post here. quick question what Solaris 10 update level included this utility? I have a bunch of Sun boxes at varying levels of Solaris 10 some have it some do not. When I do my install I take the full option for the packages to install on all the systems. thanks in advance... Mike (4 Replies)
Discussion started by: mike_243us
4 Replies

5. Shell Programming and Scripting

matching a pattern in a file & prefixing a word

Hi, In my shell script i have to match a patten in a file , if found i have to prefix the entair line by a "word" eg. pattern = "aaa" prefix= #123 file: bbbb xxx zzzz aaaa qqqq kkkk outPut file: bbbb xxx ... (5 Replies)
Discussion started by: shivarajM
5 Replies

6. Shell Programming and Scripting

CSV formatting with prefixing, appending and padding field

Hi I have a very large csv file with some hundreds of thousands of rows of data. The data is in the following format: Up to four alpha numeric characters for the first word. This is either set as 2 characters followed by 2 spaces, or as a single 4character word. This is then followed by an 8... (7 Replies)
Discussion started by: meself
7 Replies

7. Shell Programming and Scripting

prefixing filenames

Hi,:cool: I have a list of files in a directory.I need to store them in a file with the prefix of @ by using a command.. ex:@p_po.plb @p_ebiz_roster_data.plb any idea pls. cheers RRK (2 Replies)
Discussion started by: ravi raj kumar
2 Replies
Login or Register to Ask a Question