Creating 12 digit string value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating 12 digit string value
# 1  
Old 09-27-2010
Creating 12 digit string value

Hi Masters,

here is my req
I have to create a 12 digit string which includes the user i/p

Like if user input 2334 then the string will be 233411111111 ,if the user inputs 23345 then the string will be 233451111111 ,

So we dont know how many digits will the user inputs output will be 12 digit with user input comes first

Please help
# 2  
Old 09-27-2010
#deleted#

---------- Post updated at 04:23 AM ---------- Previous update was at 04:14 AM ----------

Code:
$ echo "1234" | ruby -e 's=gets.chomp![0,12];s<<"1"*(12-s.size);p s'
"123411111111"


Last edited by kurumi; 09-27-2010 at 06:22 AM..
# 3  
Old 09-27-2010
Bug

Hi Kurumi,

Thnks a lot for your help .
But ruby is not installed ,is there any other way round.

Thanks for your reply and please provide me a another way
# 4  
Old 09-27-2010
Code:
$ a=$(printf "%-12s" "1234")
$ echo ${a// /1}
123411111111

# 5  
Old 09-27-2010
Hi kurumi ,

Thanks a lot..............
U r a genious...


Smilie
# 6  
Old 09-27-2010
Another one:
Code:
$ echo "1234" | awk '{$(13-length)=""}1' OFS="1"
123411111111

# 7  
Old 09-27-2010
Hi Franklin ,

Thanksssssssssss a lot..

As always you are a gr8 help
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash: Getting first digit of a string

If i'm given a string like "abc-def-1.2.3", how would I return "1"? I'm new to scripting and got stumped on this problem. Thanks in advance! (7 Replies)
Discussion started by: atsim
7 Replies

2. Programming

Creating a string

I am trying to create a string from two strings using the following code and getting the following code and getting the warning In file included from ./prgms/raytrac.cc:62:0: baselib/clorfncs.hh: In function ‘void pr_hmisc(FILE*, int)’: baselib/clorfncs.hh:494:21: warning: deprecated... (2 Replies)
Discussion started by: kristinu
2 Replies

3. Shell Programming and Scripting

How to delete only the last digit in string

Hello, I would like to convert this string KBL3TEST1 into KBL3TEST How can i code this? Any help is appreciated regards, blashyou (6 Replies)
Discussion started by: blashyou
6 Replies

4. 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

5. 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

6. Shell Programming and Scripting

Check whether a string begin with uppercase, lowercase or digit!

Hi every body! I wrote script on Fedora (bash shell) to check whether a tring enter from user console is start with a uppercase/lowercase letter or a digit. But with this script i have some problem when I enter from character from 'b' to 'z' --> result is uppercase. This code look like ok but i... (9 Replies)
Discussion started by: nguyendu0102
9 Replies

7. Shell Programming and Scripting

Single digit date to double digit date.

I have a var storing date var=`date` Now the date is returned as Mon Feb 2 00:25:48 PST 2009 Is there any way to check the date field alone ("2" in above case) and if its a single digit then add a prefix 0 to it and store the result in same variable "var" My intention in above case is... (3 Replies)
Discussion started by: villain41
3 Replies

8. Shell Programming and Scripting

Find first digit in string using expr index

I have looked for hours for an answer, so I have decided to request your guidance. I want to substract the first number (series of digits) contained in a string. This string is the output of another command. The substring (number) can be located at any position inside the string. I want to... (4 Replies)
Discussion started by: jcd
4 Replies

9. Shell Programming and Scripting

How to convert a 2 digit to 4 digit

Hi All, How can i convert a number 24 to 0024 In the same way how can i convert 123 to 0123? All this has to be done inside a script Thanks in advance JS (6 Replies)
Discussion started by: jisha
6 Replies

10. 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
Login or Register to Ask a Question