adding a 6 digit number retaining 0s on the left


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting adding a 6 digit number retaining 0s on the left
# 1  
Old 03-08-2007
Question adding a 6 digit number retaining 0s on the left

i am new to shell scripting. i want to keep on increamenting a 6 digit number. For eg. 000000 + 1 = 000001 But instead of 000001 i get only 1. How do i do this ? Pls help.
# 2  
Old 03-08-2007
Code:
x=$( printf "%06d" $( expr 000000 + 1 ) )

# 3  
Old 03-08-2007
to change one of the tokens of a filename

Thanks so much. It works fine Smilie
One more thing, I have a file like “uuu.1.2.090909.gz.111”.
I just want to change the 4th token, like “uuu.1.2.050505.gz.111”. How can I do in minimum steps?
# 4  
Old 03-08-2007
Code:
mv uuu.1.2.090909.gz.111 $( echo "uuu.1.2.090909.gz.111" | awk -F"." -v OFS="." ' $4 = 050505 ' )

# 5  
Old 03-08-2007
Code:
echo uuu.1.2.090909.gz.111 | sed 's/\(.*\)\.\(.*\)\.\(.*\)\.\(.*\)\.\(.*\)\.\(.*\)/\1.\2.\3.050505.\5.\6/'

Code:
echo uuu.1.2.090909.gz.111 | sed 's/9/5/g'

# 6  
Old 03-08-2007
not working

i need to use variable for the filename(uuu.1.2.090909.gz.111) and for the 4the token also (050505).it works with the actual values but when i replace with variables it doesnt.can u pls help ???

Last edited by kanchan_cp; 03-08-2007 at 09:11 AM..
# 7  
Old 03-08-2007
Code:
src=uuu.1.2.090909.gz.111
replace=050505
echo $src | sed "s/\(.*\)\.\(.*\)\.\(.*\)\.\(.*\)\.\(.*\)\.\(.*\)/\1.\2.\3.$replace.\5.\6/"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Process only 4 digit odd number starting with zero

I am trying to process only IonCode_odd #'s (always 4 digits starting with zero), but the below isn't working as expected. Is there a better way? Thank you :). IonCode_0401_xxxx_xxxx_xxxx.bam IonCode_0401_xxxx_xxxx_xxxx.bam.bai IonCode_0401_xxxx_xxxx_xxxx.fastq... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

How to compare specific digit in number?

Dear All, Lets say I have a number with following format: ####.12e-## now I want to compare place holder in position 1 and 2. How can I do that? Note: My number is stored in a variable say var. example: var=9999.12e-05 Thanks & Regards, linuxUser_ (6 Replies)
Discussion started by: linuxUser_
6 Replies

3. Shell Programming and Scripting

Regular expression for 6 digit number present in a line

Hello Team, i have a file test1.txt, in which i have to grep only the 6 digit number from it, Could you pls help in this. $cat test1.txt <description>R_XYZ_1.6 r370956</description> $ grep "\{6\}" test1.txt <description>R_XYZ_1.6 r370956</description> i need output as 370956. ... (3 Replies)
Discussion started by: chandana hs
3 Replies

4. Shell Programming and Scripting

Print a number up to last significant digit after decimal point

I want to write/print a number through a shell script up to its last significant digit (LSD) after the decimal point. Say, x=10.00056000000000000 I want to print x as x=10.00056. Note that x can be any thing so I cannot know the position of the LSD always. Thanks. (16 Replies)
Discussion started by: hbar
16 Replies

5. Shell Programming and Scripting

Adding Zeros to make it 8 digit

Dear Buddies, My query may be pretty simple but I am stuck because of it. Please give me a solution. Query is I have a variable (say $A) which can have any number starting from 1 digit to 8 digit i.e. any number from 1 to 99999999. Now, I want output as 8 digit even if variable has only 1 digit.... (3 Replies)
Discussion started by: anushree.a
3 Replies

6. UNIX for Dummies Questions & Answers

list all files containing 4 digit number using grep

how can i list all files in my home directory that have a 4 digit id number, the line number where the id is located and the id itself not printing the entire line? (5 Replies)
Discussion started by: hobiwhenuknowme
5 Replies

7. Programming

Find out 2^n+1 , where n is a 3 digit number

I have to write a c program which takes a 3 digit number n and calculates the value of (2^n)+1 and then determines the number is prime or not. I have tried to first calculate the value of 2^n and then adding one to it and then apply the logic of prime number. but the ultimate problem is that... (7 Replies)
Discussion started by: agrawal.prachi
7 Replies

8. Programming

generating 16 digit random number in C

Hi, How can we generate 16 digit random nos in C. (10 Replies)
Discussion started by: ajaysahoo
10 Replies

9. Shell Programming and Scripting

calculate the number of days left in a month

does any one have any ideas how i would go about calculating the number of days left in the month from a bash script ?. I want to do some operations on a csv file according to the result (8 Replies)
Discussion started by: dunryc
8 Replies

10. Shell Programming and Scripting

Extracting 10 digit number from txt files

Hi, Was wondering if you could give me an example of extracting a 10 digit number from 5 txt files using a regular expression (the number is always different ) and storing the numbers in variables Thanks C19 (9 Replies)
Discussion started by: c19h28O2
9 Replies
Login or Register to Ask a Question