# AWK and hex sequences

**URL:** <https://community.unix.com/t/awk-and-hex-sequences/144403>\
**Category:** Shell Programming and Scripting\
**Created:** [October 10, 2002, 1:16pm UTC](https://community.unix.com/t/awk-and-hex-sequences/144403 "2002-10-10T13:16:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JoeTheGuy](https://community.unix.com/letter_avatar/joetheguy/32/6_449c533f586939b6e5f246632a46421f.png) [@JoeTheGuy](https://community.unix.com/u/JoeTheGuy)\
**Post date:** [October 10, 2002, 1:16pm UTC](https://community.unix.com/t/awk-and-hex-sequences/144403/1 "2002-10-10T13:16:19Z")

</div>

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 1 256?  
how would I "seqhex 00 ff"?  
????????????????????????????????????????????????????

---

<div class="post-metadata">

**Author:** ![system](https://community.unix.com/uploads/default/original/2X/c/c7e9e16a595259edafe88615719d5c5dcda035c2.png) [@system](https://community.unix.com/u/system)\
**Post date:** [October 14, 2002, 11:13am UTC](https://community.unix.com/t/awk-and-hex-sequences/144403/2 "2002-10-14T11:13:13Z")

</div>

try this :

#!/bin/ksh  
for i in `cat numbers.txt | awk '{ print "10#"$0}'`  
do  
typeset -i16 i  
echo $i | sed -e s/16\#//g  
done

ps.: The file called numbers.txt, has decimal numbers.

I hope help you

Witt

---

<div class="post-metadata">

**Author:** ![JoeTheGuy](https://community.unix.com/letter_avatar/joetheguy/32/6_449c533f586939b6e5f246632a46421f.png) [@JoeTheGuy](https://community.unix.com/u/JoeTheGuy)\
**Post date:** [October 16, 2002, 3:44am UTC](https://community.unix.com/t/awk-and-hex-sequences/144403/3 "2002-10-16T03:44:45Z")

</div>

not exactly what i'm looking for and it actually doesn't work on my system for some reason. oh well. thanks for the try.

---

<div class="post-metadata">

**Author:** ![Perderabo](https://community.unix.com/user_avatar/community.unix.com/perderabo/32/27_2.png) [@Perderabo](https://community.unix.com/u/Perderabo)\
**Post date:** [October 16, 2002, 8:37am UTC](https://community.unix.com/t/awk-and-hex-sequences/144403/4 "2002-10-16T08:37:57Z")

</div>

It's not at all obvious what you do want. I've never heard of a program called seq nor seqhex.

If you want to show a files contents in hex you should be using something like "od -tx1".

If you're just trying to count in hex, try this:

```nohighlight
#! /usr/bin/ksh
typeset -i16 i=0
while ((i <= 16#ff)) ; do
       echo ${i#16#}
       ((i=i+1))
done
exit 0

```

If you want something else, describe the problem. Don't post code that we can't run and then ask us how to do the same thing in another language. And if someone gives you a solution, don't simply post "not exactly what I'm looking for". Take another crack at telling us what it is that you actually do want.

---

<div class="post-metadata">

**Author:** ![JoeTheGuy](https://community.unix.com/letter_avatar/joetheguy/32/6_449c533f586939b6e5f246632a46421f.png) [@JoeTheGuy](https://community.unix.com/u/JoeTheGuy)\
**Post date:** [October 17, 2002, 3:32am UTC](https://community.unix.com/t/awk-and-hex-sequences/144403/5 "2002-10-17T03:32:20Z")

</div>

sure. i want to have a simple method of executing the output to an increment of 1 to 256 but in hexidecimal numbers.  
My question is how do I on the fly, convert  
the ouput of "seq 1 256" to it's corresponding hexadecimal equivalents. that's all I need to know. Not wanting to know how to take a hexdump of a file, or number the lines of a file in hex or anything like that. I merely want to use the bash shell in combination with really whatever has to be used to generate a hexidecimal number sequence of 00 to FF.  
If you can help please do so. Thanks for the help by the way. I appreciate it.

---

<div class="post-metadata">

**Author:** ![Perderabo](https://community.unix.com/user_avatar/community.unix.com/perderabo/32/27_2.png) [@Perderabo](https://community.unix.com/u/Perderabo)\
**Post date:** [October 17, 2002, 8:17am UTC](https://community.unix.com/t/awk-and-hex-sequences/144403/6 "2002-10-17T08:17:33Z")

</div>

How about:

```nohighlight
#! /usr/local/bin/bash
declare -i i=0
while ((i <= 16#FF)) ; do
      X=$(printf "%X\n" $i)
      echo ${X#0X}
      ((i=i+1))
done
exit 0

```
