Sponsored Content
Top Forums Shell Programming and Scripting Covert Deci to Hex (New to AWK) Post 70873 by zazzybob on Wednesday 4th of May 2005 09:59:34 PM
Old 05-04-2005
Code:
$ more file
Wregister( 45676, 0)
Wregister( 55550, 1)
Wregister( 44000, 0)
FlipFlop( 2342, 2)
$ more file.sh 
#!/bin/sh

while read line; do
  echo "$line" | grep "^Wreg" >/dev/null 2>&1
  if [ "$?" -eq "0" ]; then
     val=`echo "$line" | sed 's/^Wregister*([ ]*\([0-9]*\),.*$/\1/'`
     hex=`echo "obase=16;ibase=10; $val" | bc`
     echo "$line" | sed "s/$val/$hex/"
  else
     echo "$line"
  fi
done < file

exit 0
$ chmod +x ./file.sh
$ ./file.sh > newfile
$ more newfile
Wregister( B26C, 0)
Wregister( D8FE, 1)
Wregister( ABE0, 0)
FlipFlop( 2342, 2)

Cheers
ZB
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

AWK and hex sequences

for file in `seq 1 256`; do printf "\x$file -- $file" ; done ; printf "\n" produces the wrong output. I want to show the ascii codes but need to output a hexidecimal number sequence. I know I should use awk to do this but i'm not sure how cause I forget. what is the awk equivelant of seq... (5 Replies)
Discussion started by: JoeTheGuy
5 Replies

2. Programming

After converting the hexstr to Hex and storing the Hex in a char*

Hi All, My main intension of is to convert the Hexstring stored in a char* into hex and then prefixing it with "0x" and suffix it with ',' This has to be done for all the hexstring char* is NULL. Store the result prefixed with "0x" and suffixed with ',' in another char* and pass it to... (1 Reply)
Discussion started by: rvan
1 Replies

3. Programming

What is the difference between ios::hex and std::hex?

Hi, Is there really a difference between these two, std::hex and ios::hex?? I stumbled upon reading a line, "std::ios::hex is a bitmask (8 on gcc) and works with setf(). std::hex is the operator". Is this true? Thanks (0 Replies)
Discussion started by: royalibrahim
0 Replies

4. Shell Programming and Scripting

awk to remove leading zeros for a hex number

Is it possible by using awk to remove leading zeros for a hex number? ex: 0000000011179E0A -> 11179E0A Thank you! (4 Replies)
Discussion started by: carloszhang
4 Replies

5. UNIX for Dummies Questions & Answers

How to specify a FS as HEX value in AWK

Hi All, I have one input file seperated with Hex decimal B1 value. And i want to process this file. And iam creating an awk script to process this file. How can I specify the Field seperator as HEX B1 in my awk. Please help. Thanks in advance.:) (2 Replies)
Discussion started by: psk_kumar
2 Replies

6. Shell Programming and Scripting

Range of numbers in HEX using AWK

Hi , How do i found out all the number in a range ( HEX) for example Input is 15CF:15D2 Output needed 15CF 15D0 15D1 15D2 Thanks (2 Replies)
Discussion started by: greycells
2 Replies

7. Shell Programming and Scripting

how to get data from hex file using SED or AWK based on pattern sign

I have a binary (hex) file I need to parse to get some data which are encoded this way: .* b4 . . . 01 12 .* af .* 83 L1 x1 x2 xL 84 L2 y1 y2 yL By another words there is a stream of hexadecimal bytes (in my example separated by space for better readability). I need to get value stored in... (3 Replies)
Discussion started by: sameucho
3 Replies

8. Shell Programming and Scripting

awk to compare hex number

$ awk 'BEGIN{ pat111=0x1000000002E3E02; snBegin=0x1000000002E3E01; if (pat111<=snBegin) printf "a\n"}' a Result is not correct. Looks like the number is too big. Any idea? Thx! Please use code tags <- click the link! (2 Replies)
Discussion started by: carloszhang
2 Replies

9. HP-UX

Replacing Hex Characters In A File Using awk?

Hi guys, First off, i'm a complete noob to UNIX and LINUX so apologies if I don't understand the basics! I have a file which contains a hex value of '0D' at the end of each line when I look at it in a hex viewer. I need to change it so it contains a hex value of '0D0A0A' I thought... (10 Replies)
Discussion started by: AndyBSG
10 Replies

10. Shell Programming and Scripting

Print hex Ip address in decimal format inside awk script

Hi to all, May someone help me with the following. The awk script below is part of a bigger awk script, and this part attempts to print an Ip address that is in hex format in decimal format. I'm trying with following code but I'm getting 0.0.0.0 and the correct answer is 192.168.140.100 ... (9 Replies)
Discussion started by: Ophiuchus
9 Replies
INI_GET(3)								 1								INI_GET(3)

ini_get - Gets the value of a configuration option

SYNOPSIS
string ini_get (string $varname) DESCRIPTION
Returns the value of the configuration option on success. PARAMETERS
o $varname - The configuration option name. RETURN VALUES
Returns the value of the configuration option as a string on success, or an empty string for null values. Returns FALSE if the configura- tion option doesn't exist. EXAMPLES
Example #1 A few ini_get(3) examples <?php /* Our php.ini contains the following settings: display_errors = On register_globals = Off post_max_size = 8M */ echo 'display_errors = ' . ini_get('display_errors') . " "; echo 'register_globals = ' . ini_get('register_globals') . " "; echo 'post_max_size = ' . ini_get('post_max_size') . " "; echo 'post_max_size+1 = ' . (ini_get('post_max_size')+1) . " "; echo 'post_max_size in bytes = ' . return_bytes(ini_get('post_max_size')); function return_bytes($val) { $val = trim($val); $last = strtolower($val[strlen($val)-1]); switch($last) { // The 'G' modifier is available since PHP 5.1.0 case 'g': $val *= 1024; case 'm': $val *= 1024; case 'k': $val *= 1024; } return $val; } ?> The above example will output something similar to: display_errors = 1 register_globals = 0 post_max_size = 8M post_max_size+1 = 9 post_max_size in bytes = 8388608 NOTES
Note When querying boolean values A boolean ini value of off will be returned as an empty string or "0" while a boolean ini value of on will be returned as "1". The function can also return the literal string of INI value. Note When querying memory size values Many ini memory size values, such as upload_max_filesize, are stored in the php.ini file in shorthand notation. ini_get(3) will return the exact string stored in the php.ini file and NOT its integer equivalent. Attempting normal arithmetic functions on these values will not have otherwise expected results. The example above shows one way to convert shorthand notation into bytes, much like how the PHP source does it. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.3.0 | | | | | | | Previously, the empty string was returned if the | | | configuration option didn't exist. now, FALSE is | | | returned instead. | | | | +--------+---------------------------------------------------+ SEE ALSO
get_cfg_var(3), ini_get_all(3), ini_restore(3), ini_set(3). PHP Documentation Group INI_GET(3)
All times are GMT -4. The time now is 08:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy