The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Converting \0 to a \n ajcannon Shell Programming and Scripting 2 09-28-2007 11:30 AM
sed converting / to \/ sakthi.abdullah UNIX for Advanced & Expert Users 8 12-14-2006 03:56 AM
Converting seeyou SCO 3 01-19-2006 02:22 PM
converting .txt laila63 UNIX for Dummies Questions & Answers 4 06-30-2004 04:56 PM
converting kb to mb csaunders UNIX for Dummies Questions & Answers 1 02-26-2004 04:14 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-26-2008
aismann aismann is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 37
converting hex to dec

Hi Experts,

I have a file called "hex" which contains info like below
Quote:
0x0DD
0x1E9
0x1EA
0x1EB
0x1F4
0x1F7
0x1F9
0x1FE
0x202
0x203
0x208
0x209
0x20E
0x20F
0x210
How do i convert everything in this file to decimal value? Please advice. Thanks
  #2 (permalink)  
Old 02-26-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
One solution:

Code:
cat hex | while read value
do
 printf "%d\n" $value
done
Regards
  #3 (permalink)  
Old 02-26-2008
aismann aismann is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 37
Hi Franklin,

This is what i get

Quote:
root@ckpgpay11core> cat hex| while read value; do printf "%d\n" $value; done
bash: printf: 0x0DD: illegal number
bash: printf: 0x0DE: illegal number
bash: printf: 0x0E1: illegal number
bash: printf: 0x0E2: illegal number
bash: printf: 0x0E3: illegal number
bash: printf: 0x0E4: illegal number
bash: printf: 0x0E5: illegal number
bash: printf: 0x0E6: illegal number
bash: printf: 0x0E7: illegal number
bash: printf: 0x0E8: illegal number
bash: printf: 0x0F2: illegal number
bash: printf: 0x1A4: illegal number
bash: printf: 0x1B8: illegal number
bash: printf: 0x1B9: illegal number
bash: printf: 0x1BA: illegal number
bash: printf: 0x1BB: illegal number
  #4 (permalink)  
Old 02-26-2008
aismann aismann is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 37
even after removing the "0x"

Quote:
root@ckpgpay11core> cat sara2 | while read value; do printf "%d\n" $value; done
bash: printf: 0DD: illegal number
bash: printf: 0DE: illegal number
bash: printf: 0E1: illegal number
bash: printf: 0E2: illegal number
bash: printf: 0E3: illegal number
bash: printf: 0E4: illegal number
bash: printf: 0E5: illegal number
bash: printf: 0E6: illegal number
bash: printf: 0E7: illegal number
bash: printf: 0E8: illegal number
bash: printf: 0F2: illegal number
bash: printf: 1A4: illegal number
  #5 (permalink)  
Old 02-26-2008
chella chella is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 75
Hi,

Use typeset command in UNIX to do the conversion. I think you need to used typeset -i. Try typeset after removing '0x'.

Regards,
Chella
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0