|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to convert a file containing hex code to decimal using script?
The file contains code like the below and need to convert each one into a decimal
00 00 00 04 17 03 06 01 So the output should come as 0 0 0 4 23 3 6 1 |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Code:
$ for i in 00 00 00 04 17 03 06 01 ; do echo "ibase=16; $i" | bc ; done |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Without external programs Code:
for i in 00 00 00 04 17 03 06 01 ; do printf "%d\n" "0x$i" done |
|
#4
|
|||
|
|||
|
Hi Jayan
I have a file called hex.txt the file contains numerous entries i, just gave 8 as an example , I need to pick up entire content from the file and convert to decimal and not just those 8 alone Can u advise if that is possible |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Please post a representative sample of hex.txt and the desired output..
|
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
hex.txt contains numerous entries like this Code:
00 00 00 04 0A 02 05 01 00 00 00 00 0A 0A 32 C7 00 00 00 00 0A 0A 32 F3 0A 0A 2B 2D 00 00 00 00 00 00 00 08 80 01 06 6D 26 E4 00 02 00 00 00 00 06 6D 0A 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 So for eg : 00 00 00 04 0A 02 05 01 should be converted into decimal form 0 0 0 4 10 2 5 1 and so on Last edited by Franklin52; 05-31-2012 at 03:59 AM.. Reason: Please use code tags |
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
Try: Code:
awk '{for(i=1;i<=NF;i++)$i=sprintf("%0d","0x"$i)}1' infile |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Convert decimal notation to ANSI point code notation | aavam | Shell Programming and Scripting | 4 | 06-28-2011 09:16 PM |
| To convert file with decimal to another file with Hexadecimal | mathie | Shell Programming and Scripting | 10 | 06-08-2011 02:50 AM |
| Convert exponential value to decimal | Sangtha | Shell Programming and Scripting | 5 | 07-23-2009 12:04 AM |
| PERL:How to convert numeric values txt file to PACKED DECIMAL File? | aloktiwary | Shell Programming and Scripting | 1 | 05-20-2009 09:55 AM |
| having a bash script convert ft to meters with 1 decimal | audiophile | Shell Programming and Scripting | 2 | 09-14-2008 10:00 AM |
|
|