Decimal conversion number of the form x.xx to 0x.xx, sed?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Decimal conversion number of the form x.xx to 0x.xx, sed?
# 8  
Old 09-12-2014
All right, I thought it were literal num's Smilie Try this:
Code:
sed 's/^\([0-9]\{18\}\)  \([0-9]\)\./\1 0\2\./'

This User Gave Thanks to junior-helper For This Post:
# 9  
Old 09-12-2014
Quote:
Originally Posted by junior-helper
All right, I thought it were literal num's Smilie Try this:
Code:
sed 's/^\([0-9]\{18\}\)  \([0-9]\)\./\1 0\2\./'

Thank you it works! can you please explain what you did? to know what to do when I want to do it for e.g. the 5th column
# 10  
Old 09-12-2014
You're welcome. This sed command makes use of "group capturing" and does following:

Short version: It matches a pattern of 18 numbers (from the beginning of the line, this is represented by the "^" sign) followed by 2 whitespaces followed by one number followed by a literal dot.

If matched, then following happens:
Collect the first 18 numbers, from the beginning of the line and put them in a "variable" called "1".
Collect the next single number (followed by a dot) and put it a "variable" called "2".

The whole matched pattern gets replaced by \1 0\2\.
\1 means that the variable 1 is being "restored"
whitespace
(preceding) zero
\2 variable 2 is being "restored"
\. is a escaped dot, thus a literal dot.

I hope this is understandable.

---------- Post updated at 04:58 PM ---------- Previous update was at 04:53 PM ----------

To perform the conversion on the fifth column, you could try this:
Code:
sed 's/^\(.\{35\}\)  \([0-9]\)\./\1 0\2\./'
The red dot means any character/number/sign.

This User Gave Thanks to junior-helper For This Post:
# 11  
Old 09-12-2014
Thank you again I am grateful! u r an inspiration!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

SED - how do I convert a decimal number to asterisk

Hi, My animal ID's have two zeros in them and are also converting to asterisk. I only need to change the zero values in columns two and three. I would appreciate any help. This is my data structure: head phendata.txt 201008809 0.0 0.0 201008810 0.0 0.0 201008813 0.0 0.0 201014103... (6 Replies)
Discussion started by: lel7lel7
6 Replies

2. Shell Programming and Scripting

NAWK conversion of hexadecimal input to decimal output via printf, I am close I can feel it

I have searched and the answers I have found thus far have led me to this point, so I feel I am just about there. I am trying to convert a column of hexadecimal to decimal values so that I can filter out via grep just the data I want. I was able to pull my original 3 character hex value and... (10 Replies)
Discussion started by: PCGameGuy
10 Replies

3. Shell Programming and Scripting

number of digits after decimal

Hi All, I have a file of decimal numbers, cat file1.txt 1.1382666907 1.2603107334 1.6118799297 24.4995857056 494.7632588468 560.7633734425 ..... I want to see the output as only 7 digits after decimal (5 Replies)
Discussion started by: senayasma
5 Replies

4. Shell Programming and Scripting

IP address to decimal format conversion

I have a file which consist of some class 4 IP address as 172.16.112.50 172.16.112.50 172.16.112.50 172.16.112.100 192.168.1.30 172.16.112.100 172.16.112.50 172.16.112.50 172.16.112.50 i want to store them in pure decimal notations instead of the given dotted decimal formats e.g.... (2 Replies)
Discussion started by: vaibhavkorde
2 Replies

5. Shell Programming and Scripting

changing number in bash (number is in form of string)

I have a txt file as database. when i run my program what it does is it ask me for 3 name and stored in the file as name1:name2:name3:1 when u enter 3 name it add those in file as above format and add 1 at the end. I what i want is if i enter same names again it changes that 1 to 2 and so... (3 Replies)
Discussion started by: Learnerabc
3 Replies

6. Shell Programming and Scripting

Add zero in decimal number

echo "scale=2; 282.73/640" | bc This will print .44 How to make the variable as 0.44 (2 Replies)
Discussion started by: sandy1028
2 Replies

7. Shell Programming and Scripting

Decimal to hex conversion

Dear All PROs Thanks in advance need a shell for Decimal to hex conversion input file (decimal values) 65,5,48,66,133,131,118,47 65,5,48,66,133,131,83,63 . . desire output should be (Hex value)... (11 Replies)
Discussion started by: The_Archer
11 Replies

8. Shell Programming and Scripting

need help with ascii to decimal conversion

Hi, Can anyone please help me ascci to decimal conversion in bash I have a file which contains stream of numbers like this,these are ascci values 729711810132973278105991013268971213233 I want to covert it to its actual value like upper code's decimal is "Have a Nice Day!" ... (15 Replies)
Discussion started by: sunilmenhdiratt
15 Replies

9. Shell Programming and Scripting

Decimal to Hexadecimal conversion

Hi frnds :) I need a small help... I have a very long file containing 20 digits decimal number which i want to convert into the corresponding 16 digit hexadecimal values. File looks like.... 11908486672755551741 05446378739602232559 04862605079740156652 . . . I tried the script for i... (7 Replies)
Discussion started by: vanand420
7 Replies
Login or Register to Ask a Question