Sponsored Content
Top Forums Shell Programming and Scripting Adding Zeros to make it 8 digit Post 302602638 by anushree.a on Tuesday 28th of February 2012 01:01:40 AM
Old 02-28-2012
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. IT can be accomplished by addting Zeros (0) before the value of $A.

E.g 1)

$A=1
then output should be printed as 00000001

E.g 2)
$A=1234
then output should be printed as 00001234

E.g. 3)
$A=1234567
then output should be printed as 01234567

E.g 4)
$A=12345678
then output should be printed as 12345678 (As it is because it is already 8 digit number)

Last edited by fpmurphy; 02-28-2012 at 10:17 PM.. Reason: remove colors and fonts
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

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. (8 Replies)
Discussion started by: kanchan_cp
8 Replies

2. Shell Programming and Scripting

Replace one digit by two digit using sed

Folks, Is there a simple way to replace one digit by two digit using sed. Example, mydigit1918_2006_8_8_lag1.csv should be mydigit1918_2006_08_08_lag01.csv. I tried this way, but doesn't work. echo mydigit1989_2006_8_8_lag1.csv|sed 's/]/0]/' Thank you, (5 Replies)
Discussion started by: Jae
5 Replies

3. Shell Programming and Scripting

using awk make an field as 5 digit and display

using awk convert 3 rd fileld of file as 5 digit and then display changed file. like 1 2 23445 3452 3343 3 5 6 6 ================ o/p:- 1 2 23445 3452 03343 3 5 00006 6 (1 Reply)
Discussion started by: RahulJoshi
1 Replies

4. Shell Programming and Scripting

Trim leading zeros to make field 6 characters long

Hi all- I've got a file that will have multiple columns. In one column there will be a string that is 10 digits in length, but I need to trim the first four zeros to make it 6 characters? example: 0000001234 0000123456 0000234566 0000000321 output: 001234 123456 234566 000321 (5 Replies)
Discussion started by: Cailet
5 Replies

5. Shell Programming and Scripting

Help with adding leading zeros to a filename

Hi i need help in adding leading zero to filenames e.g file name in my folder are 1_234sd.txt 23_234sd.txt the output i need is 001_234sd.txt 023_234sd.txt can i do this shell scripting please help (2 Replies)
Discussion started by: rsmpk
2 Replies

6. Shell Programming and Scripting

awk length of digit and print at most right digit

Have columns with digits and strings like: input.txt 3840 3841 3842 Dav Thun Tax Cahn 146; Dav. 3855 3853 3861 3862 Dav Thun Tax 2780 Karl VI., 3873 3872 3872 Dav Thun Tax 3894 3893 3897 3899 Dav Thun Tax 403; Thun 282. 3958 3959 3960 Dav Thun Tax 3972 3972 3972 3975 Dav Thun Tax... (8 Replies)
Discussion started by: sdf
8 Replies

7. Shell Programming and Scripting

Find filenames with three digits and add zeros to make five digits

Hello all! I've looked all over the internet and this site and have come up a loss with an easy way to make a bash script to do what I want to do. I have a file with a naming convention as follows: 2012-01-18 string of words here 123.jpg 2012-01-18 string of words here 1234.jpg 2012-01-18... (2 Replies)
Discussion started by: Buzzman25
2 Replies

8. Shell Programming and Scripting

convert two digit in to single digit...

Hi Guys. My Input: ABCD 12 00 KL ABCD 12 08 DL ABCD 12 10 KK ABCD 12 04 LL ABCD 13 00 LP ABCD 13 1O LS Output: ABCD 12 0 KL ABCD 12 8 DL ABCD 12 10 KK ABCD 12 4 LL ABCD 13 0 LP (2 Replies)
Discussion started by: pareshkp
2 Replies

9. Shell Programming and Scripting

Fixed with file- removing leading zeros and adding the space

Hi All, i have a fixed width file , where each line is 3200 length. File: 1ABC 1111 2222 3333 000012341 1001 2ABC 1111 2222 3333 000012342 1002 3ABC 1111 2222 3333 000112343 1003 1DEF 5555 4444 9696 000012344 1004 2DEF 5555 2323 8686 000012345 1005 3DEF 5555 1212 7676 000012346 1006 ... (1 Reply)
Discussion started by: mechvijays
1 Replies

10. Shell Programming and Scripting

Adding Leading Zeros for date in a file

Hello, I have a pipe separated file with two major lines. One is header and another is detail line. Header starts with H and Detail start with D. Sample Content: H|123456|Joes Watson|UK|4/5/2016|12/5/2016|3456|HC|NW|||||| D|123456|Joes... (13 Replies)
Discussion started by: Mannu2525
13 Replies
ISWDIGIT(3)						     Linux Programmer's Manual						       ISWDIGIT(3)

NAME
iswdigit - test for decimal digit wide character SYNOPSIS
#include <wctype.h> int iswdigit(wint_t wc); DESCRIPTION
The iswdigit function is the wide-character equivalent of the isdigit function. It tests whether wc is a wide character belonging to the wide character class "digit". The wide character class "digit" is a subclass of the wide character class "xdigit", and therefore also a subclass of the wide character class "alnum", of the wide character class "graph" and of the wide character class "print". Being a subclass of the wide character class "print", the wide character class "digit" is disjoint from the wide character class "cntrl". Being a subclass of the wide character class "graph", the wide character class "digit" is disjoint from the wide character class "space" and its subclass "blank". Being a subclass of the wide character class "alnum", the wide character class "digit" is disjoint from the wide character class "punct". The wide character class "digit" is disjoint from the wide character class "alpha" and therefore also disjoint from its subclasses "lower", "upper". The wide character class "digit" always contains exactly the digits '0' to '9'. RETURN VALUE
The iswdigit function returns non-zero if wc is a wide character belonging to the wide character class "digit". Otherwise it returns zero. CONFORMING TO
ISO/ANSI C, UNIX98 SEE ALSO
isdigit(3), iswctype(3) NOTES
The behaviour of iswdigit depends on the LC_CTYPE category of the current locale. GNU
1999-07-25 ISWDIGIT(3)
All times are GMT -4. The time now is 12:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy