Replacing the first 0 with a number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing the first 0 with a number
# 1  
Old 03-16-2009
Replacing the first 0 with a number

Hi,

Appreciate any help in advance ;-)

There are some numbers between 0 and 1, 0 not included: .2500, .3333, .5000, .6666, .7500, 1.000

How to replace the first 0 ( after the dot ) with a number, say, if the number is 3:
.2500 will be .2530
.5000 will be .5300
.7500 will be .7530

If there is no 0, the number will be appended to the end:
.3333 will be .33333
.6666 will be .66663

If the number is double digit number ( or more ), say 34, then
.2500 will be .2534
.5000 will be .5340
.7500 will be .7534

If there is no 0, the number will be appended to the end:
.3333 will be .333334
.6666 will be .666634


I'm thinking a function accepting two parameters, the first one will be the number needs to be modified ( eg. .2500, or .3333 ), the second one will be the positive number to add ( eg. 3, or 34, or 334, etc, not zero )

Any ideas, or examples will be very much welcomed.

Regards
# 2  
Old 03-16-2009
Forgot to mention, this should be done in Ksh . thanks
# 3  
Old 03-16-2009
your 2nd and 4th req are not clear.. loks same pattern and you want to do two operations.
# 4  
Old 03-17-2009
I cannot think of any real world application of that logic. Homework?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX replacing and incrementing number

Hi I am unix newbie looking for a unix bash script that can make it easier to do my code work. we have a code number for each code block that we want to incrementally assign. We have 10000 of these and it is very laborious to do this one by one. so what we want is start from the top of the... (4 Replies)
Discussion started by: chamajid
4 Replies

2. Shell Programming and Scripting

Linux Commands needed for replacing variable number of spaces with a single , in a txt file

Hi I want to read a text file and replace various number of spaces between each string in to a single "," or any other character .Please let me know the command to do so. My input file is a txt file which is the output of a SQL table extract so it contains so many spaces between each column of the... (2 Replies)
Discussion started by: Hari Prasanth
2 Replies

3. Shell Programming and Scripting

awk to find number in a field then print the line and the number

Hi I want to use awk to match where field 3 contains a number within string - then print the line and just the number as a new field. The source file is pipe delimited and looks something like 1|net|ABC Letr1|1530||| 1|net|EXP_1040 ABC|1121||| 1|net|EXP_TG1224|1122||| 1|net|R_North|1123|||... (5 Replies)
Discussion started by: Mudshark
5 Replies

4. Shell Programming and Scripting

Replacing string by incrementing number

Dear all Say I have a file as ! TICKET NBR : 234 !GSI : 102 ! 3100.2.112.1 11/06/2013 15:56:29 ! 3100.2.22.3 98 ! 3100.2.134.2 8 ! ! TICKET NBR : 1809 ! GSI : 102 ! 3100.2.112.1 11/06/2013 16:00:45 ! 3100.2.22.3 65 ! 3100.2.134.2 3 ! ! TICKET NBR : 587 ! GSI : 102 ! 3100.2.112.1... (3 Replies)
Discussion started by: OTNA
3 Replies

5. Shell Programming and Scripting

Replacing a character with a number based on lines

Hi, I am in need of help for the two things which is to be done. First, I have a file that has around four columns. The first column is filled with letter "A". There are around 400 lines in the files as shown below. A 1 5.2 3.2 A 2 0.2 4.5 A 1 2.2 2.2 A 5 2.1 ... (2 Replies)
Discussion started by: begin_shell
2 Replies

6. Shell Programming and Scripting

Replacing number between xml tags with ksh shell script

Hallo, im basically a complete noob on shell scripting and im trying to replace or rather add 1 to a number between xml tags. The xml basically has a tag somewhere that looks like this: <tag>12345678901234</tag> Now i want to replace the number between the tags. And i want the file to... (6 Replies)
Discussion started by: Demoric
6 Replies

7. Shell Programming and Scripting

Replacing line number w/spaces in DSDT compiler log

Hi, all, I'm from the 8-bit micro days (Z-80, 6809, 6502, etc.) and used to program in assembly and machine code. But, that was 25 years ago and life happened. Now, I'm scripting for the hackintosh community and love every bit of it. I'm parsing a DSDT compiler log for error/warning/remarks... (0 Replies)
Discussion started by: digital_dreamer
0 Replies

8. Shell Programming and Scripting

Replacing Port number Using Sed

Hi Im trying to replace http port value.However for some reason its not working.Can you guys take a look and hit me with suggestions please.Your help is much appreciated. echo "Enter Value" read ans sed -i "s/http-port = 80 /http-port = $ans/g" demo Note:demo is the filename ... (6 Replies)
Discussion started by: coolkid
6 Replies

9. Shell Programming and Scripting

replacing a number with random variable inside shell script

Hi All. I need help for the below logic. I ve a file like following input file: NopTX(5) // should be remain same as input ----Nop(@100); //1 Nop(90); //2 --Nop(80); //3 @Nop(70); //4 --@Nop(60); //5 @Nop@(@50); //6 --Nop@( 40); ... (3 Replies)
Discussion started by: user_prady
3 Replies
Login or Register to Ask a Question