Append 0 to a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Append 0 to a variable
# 8  
Old 06-05-2012
Code:
if [ $a -gt 0 -a $a -lt 10 ]
then
a="0$a"
fi
echo $a

SmilieSmilie

Last edited by Scrutinizer; 06-05-2012 at 04:30 AM.. Reason: code tags
# 9  
Old 06-08-2012
Quote:
Originally Posted by Nithz
getting error as

Code:
 sprintf:  not found

I am using bash shell...
My bad, sorry. I meant printf.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash - proper way to append variable to stderr

Hello, Can you please if the bellow is the proper way of appending a variable to the stderr: The easiest way to test this,I was able to imagine, was by touching 5 files and afterwards looping trough to the results: -rw-r--r-- 1 ab owner 0 Sep 14 13:45 file1 -rw-r--r-- 1 ab owner 0 Sep... (7 Replies)
Discussion started by: alex2005
7 Replies

2. Shell Programming and Scripting

How to Append data to the content at the beginning of a variable?

Hi Guys, IF i have to append data to a variable, i simply use the following. What can i do to append data to the beginning? VAR+="data" (6 Replies)
Discussion started by: srkmish
6 Replies

3. Shell Programming and Scripting

Append variable value with sed

I have a requirement where I need to add a variable value based on a pattern match. When I try this it works: sed '/IS_ETL_DEV/a\ ABCD' File1.txt > File1.tmp Now I want to replace IS _ETL_DEV with a variable like $Pattern and replace the values ABCD with a variable $Var the value "$$XYZ=1".... (4 Replies)
Discussion started by: vskr72
4 Replies

4. Shell Programming and Scripting

How to pre-append a variable string to each line in a file?

How to pre-append a variable string to each line in a file contains both single and double quotes? The variable string has no quotes in it. thank you very much. :confused: (8 Replies)
Discussion started by: dtdt
8 Replies

5. Programming

C program to read n files and append it to a variable.

I am struck in the code of handling multiple files reading and appending it into a variable. My First file's entire content I have concatenated using strcat(<char pointer>,char array) In the Second file I extract using strtstr() function and below is the code. if( fp2 != NULL){ ... (2 Replies)
Discussion started by: gameboy87
2 Replies

6. Shell Programming and Scripting

append to same string variable in loop

I want to append values to same string variable inside a recursive function that I have .. I do not want to write to any file but use a variable.. Can anyone please help with it? Thanks in advance. (6 Replies)
Discussion started by: Prev
6 Replies

7. UNIX for Dummies Questions & Answers

how do I append new lines to awk variable?

I want to build an array using awk, consisting only of a subset of lines of a file. I know how to have awk assess whether a key phrase is in a particular line, but I can't find anywhere how to then append the line containing that phrase to an array that has previously-found lines also containing... (9 Replies)
Discussion started by: pts2
9 Replies

8. Shell Programming and Scripting

Append zeros before a value as per variable

Hello- I have a variable which contains a number, I need to populate number of zeros before another value as per this variable value. for example: I have variable X whose content is 5, variable Y whose content is 123 Now append number of zeros as per variable X before varible 'Y'... (4 Replies)
Discussion started by: pasupuleti81
4 Replies

9. Shell Programming and Scripting

Append variable to only certain lines

Hi There! I'm trying to write a shell script which generates a random hexadecimal number and then appends it to the end of lines XX onwards of a certain file. XX is determined by a certain string on the previous line. Thus for example, if the input file is I search for the string... (3 Replies)
Discussion started by: orno
3 Replies

10. Shell Programming and Scripting

Extract Variable and Append it to the file

I have a file named xyz_extract_file_20091201.dat and I need to strip out 20091201 from the file name and append this value as a first field in all the records in the file. Can you please help? Thanks. Eg. Input File: xyz_extract_file_20091201.dat ------------ Campaign1,A2347,Grp_id1... (1 Reply)
Discussion started by: shekharaj
1 Replies
Login or Register to Ask a Question