'od' help...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting 'od' help...
# 1  
Old 03-18-2017
'od' help...

Hi guys, consider the code below and the resiluts below that.
(I am trying to do something with cygwin that only has 'od'.)
(I KNOW these are NOT arrays, just humour me here.)

Is it possible to do what 'hexdump' does in a single line with 'od' instead of having to add the line with 'echo' in it to produce the same output as that from 'hexdump' without the last whitespace?
(The last whitespace is not a problem.)
Code:
#!/bin/bash
# Arrays
echo ';lkaF;LKJ1234Rœπ∂"OIJ;LKƒ©¥V		NWOIEH.,Z`X ;O	ij' > /tmp/chars

ARRAY1=$( hexdump -v -e '1/1 "%u "' < /tmp/chars )

ARRAY2=$( od -An -tu1 < /tmp/chars )

hexdump -C <<< "$ARRAY1"

hexdump -C <<< "$ARRAY2"

ARRAY2=$( echo $ARRAY2 )

hexdump -C <<< "$ARRAY2"

OSX 10.12.3, default bash terminal.
Code:
Last login: Sat Mar 18 12:07:51 on ttys000
AMIGA:amiga~> cd Desktop/Code/Shell
AMIGA:amiga~/Desktop/Code/Shell> ./Arrays
00000000  35 39 20 31 30 38 20 31  30 37 20 39 37 20 37 30  |59 108 107 97 70|
00000010  20 35 39 20 37 36 20 37  35 20 37 34 20 34 39 20  | 59 76 75 74 49 |
00000020  35 30 20 35 31 20 35 32  20 38 32 20 31 39 37 20  |50 51 52 82 197 |
00000030  31 34 37 20 32 30 37 20  31 32 38 20 32 32 36 20  |147 207 128 226 |
00000040  31 33 36 20 31 33 30 20  33 34 20 37 39 20 37 33  |136 130 34 79 73|
00000050  20 37 34 20 35 39 20 37  36 20 37 35 20 31 39 38  | 74 59 76 75 198|
00000060  20 31 34 36 20 31 39 34  20 31 36 39 20 31 39 34  | 146 194 169 194|
00000070  20 31 36 35 20 38 36 20  39 20 39 20 37 38 20 38  | 165 86 9 9 78 8|
00000080  37 20 37 39 20 37 33 20  36 39 20 37 32 20 34 36  |7 79 73 69 72 46|
00000090  20 34 34 20 39 30 20 39  36 20 38 38 20 33 32 20  | 44 90 96 88 32 |
000000a0  35 39 20 37 39 20 39 20  31 30 35 20 31 30 36 20  |59 79 9 105 106 |
000000b0  31 30 20 0a                                       |10 .|
000000b4
00000000  20 20 20 20 20 20 20 20  20 20 20 35 39 20 31 30  |           59 10|
00000010  38 20 31 30 37 20 20 39  37 20 20 37 30 20 20 35  |8 107  97  70  5|
00000020  39 20 20 37 36 20 20 37  35 20 20 37 34 20 20 34  |9  76  75  74  4|
00000030  39 20 20 35 30 20 20 35  31 20 20 35 32 20 20 38  |9  50  51  52  8|
00000040  32 20 31 39 37 20 31 34  37 0a 20 20 20 20 20 20  |2 197 147.      |
00000050  20 20 20 20 32 30 37 20  31 32 38 20 32 32 36 20  |    207 128 226 |
00000060  31 33 36 20 31 33 30 20  20 33 34 20 20 37 39 20  |136 130  34  79 |
00000070  20 37 33 20 20 37 34 20  20 35 39 20 20 37 36 20  | 73  74  59  76 |
00000080  20 37 35 20 31 39 38 20  31 34 36 20 31 39 34 20  | 75 198 146 194 |
00000090  31 36 39 0a 20 20 20 20  20 20 20 20 20 20 31 39  |169.          19|
000000a0  34 20 31 36 35 20 20 38  36 20 20 20 39 20 20 20  |4 165  86   9   |
000000b0  39 20 20 37 38 20 20 38  37 20 20 37 39 20 20 37  |9  78  87  79  7|
000000c0  33 20 20 36 39 20 20 37  32 20 20 34 36 20 20 34  |3  69  72  46  4|
000000d0  34 20 20 39 30 20 20 39  36 20 20 38 38 0a 20 20  |4  90  96  88.  |
000000e0  20 20 20 20 20 20 20 20  20 33 32 20 20 35 39 20  |         32  59 |
000000f0  20 37 39 20 20 20 39 20  31 30 35 20 31 30 36 20  | 79   9 105 106 |
00000100  20 31 30 20 20 20 20 20  20 20 20 20 20 20 20 20  | 10             |
00000110  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000120  20 20 20 20 20 20 20 0a                           |       .|
00000128
00000000  35 39 20 31 30 38 20 31  30 37 20 39 37 20 37 30  |59 108 107 97 70|
00000010  20 35 39 20 37 36 20 37  35 20 37 34 20 34 39 20  | 59 76 75 74 49 |
00000020  35 30 20 35 31 20 35 32  20 38 32 20 31 39 37 20  |50 51 52 82 197 |
00000030  31 34 37 20 32 30 37 20  31 32 38 20 32 32 36 20  |147 207 128 226 |
00000040  31 33 36 20 31 33 30 20  33 34 20 37 39 20 37 33  |136 130 34 79 73|
00000050  20 37 34 20 35 39 20 37  36 20 37 35 20 31 39 38  | 74 59 76 75 198|
00000060  20 31 34 36 20 31 39 34  20 31 36 39 20 31 39 34  | 146 194 169 194|
00000070  20 31 36 35 20 38 36 20  39 20 39 20 37 38 20 38  | 165 86 9 9 78 8|
00000080  37 20 37 39 20 37 33 20  36 39 20 37 32 20 34 36  |7 79 73 69 72 46|
00000090  20 34 34 20 39 30 20 39  36 20 38 38 20 33 32 20  | 44 90 96 88 32 |
000000a0  35 39 20 37 39 20 39 20  31 30 35 20 31 30 36 20  |59 79 9 105 106 |
000000b0  31 30 0a                                          |10.|
000000b3
AMIGA:amiga~/Desktop/Code/Shell> _

If anyone will know this site will have that person.

TIA.
# 2  
Old 03-18-2017
I'm confused. I have hexdump on cygwin 2.7.0 on Windows 7. You may not have selected the right set of cygwin modules for download.

It is fun to learn by reinventing something. Is that what you are doing here?

PS: your last sentence seems to be missing something.
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 03-18-2017
Hi JM...

I am not at home at the moment so I can't give you my cygwin version. It IS the default install though on a Windows 10 machine and it only has 'od' . It does not have 'xxd' either...

And no I am not trying to re-invent the wheel but trying to obtain a fast proper array for cygwin's version of AudiioScope that works.

The method shown does work but does it in two lines where 'hexdump' does it all in one. I can leave as is, but I would prefer it if the two had a similar _dump_s within just the one line.

Not only that if it can be done then I will have learnt something...
# 4  
Old 03-18-2017
Not sure I fully understand the request (or problem). Looking at the result of
Code:
hexdump -v -e '1/1 "%u "'  tmpchars
59 108 107 97 70 59 76 75 74 49 50 51 52 82 197 . . .

I get a similar one with
Code:
od -An -tu1 -w100 tmpchars 
  59 108 107  97  70  59  76  75  74  49  50  51  52  82 197 . . .

The main difference being that hd's bytes are printed with a separating space while od's are right justified in a four- char field. All this may of course be version dependent.
This User Gave Thanks to RudiC For This Post:
# 5  
Old 03-18-2017
Hi JM...
Apologies if this attaches itself to my previous post, I don't know how to separate them...

Well I feel an absolute idiot now. My Windows 10 machine has CygWin Version 2.6.1 and it does indeed have 'hexdump' but still not 'xxd'...

I checked my Windows 8.1 machine but forgot to get the version number of CygWin and that does NOT have 'hexdump' so unless people people have late versions of CygWin then effectively 'od' is all I have FTTB. So I will make a note to remove 'od' in the future...
I just wondered if I could condense the two lines into the one single 'od' command...

---------- Post updated at 05:16 PM ---------- Previous update was at 05:02 PM ----------

Hi RudiC...

Well after discovering my Windows 10 machine's CygWin has 'hexdump' I will eventually steer this way, but, I am creating AudioScope on Apple MBP and the BSD 'od' does not have the '-w[width]' option. However CygWin's 'od' does and seems to work, as I know the file length will always be fixed then this could be a real bonus.

Thanks a lot. I will experiment with this option...
# 6  
Old 03-18-2017
The macOS Sierra BSD-based od doesn't have -w width, but in addition to -b (to print bytes in octal), you also have the standard -t x1j (to print bytes in hex), -t u1 (to print bytes as unsigned decimal), -t d1 (to print bytes as signed decimal), and -t o1 (a synonym for -b). For example:
Code:
echo ';lkaF;LKJ1234Rœπ∂"OIJ;LKƒ©¥V		NWOIEH.,Z`X ;O	ij' |
    od -An -tco1d1u1x1

produces the output:
Code:
           ;   l   k   a   F   ;   L   K   J   1   2   3   4   R   œ  **
          073 154 153 141 106 073 114 113 112 061 062 063 064 122 305 223
           59 108 107  97  70  59  76  75  74  49  50  51  52  82 -59-109
           59 108 107  97  70  59  76  75  74  49  50  51  52  82 197 147
           3b  6c  6b  61  46  3b  4c  4b  4a  31  32  33  34  52  c5  93
           π  **   ∂  **  **   "   O   I   J   ;   L   K   ƒ  **   ©  **
          317 200 342 210 202 042 117 111 112 073 114 113 306 222 302 251
          -49-128 -30-120-126  34  79  73  74  59  76  75 -58-110 -62 -87
          207 128 226 136 130  34  79  73  74  59  76  75 198 146 194 169
           cf  80  e2  88  82  22  4f  49  4a  3b  4c  4b  c6  92  c2  a9
           ¥  **   V  \t  \t   N   W   O   I   E   H   .   ,   Z   `   X
          302 245 126 011 011 116 127 117 111 105 110 056 054 132 140 130
          -62 -91  86   9   9  78  87  79  73  69  72  46  44  90  96  88
          194 165  86   9   9  78  87  79  73  69  72  46  44  90  96  88
           c2  a5  56  09  09  4e  57  4f  49  45  48  2e  2c  5a  60  58
               ;   O  \t   i   j  \n                                    
          040 073 117 011 151 152 012                                    
           32  59  79   9 105 106  10                                    
           32  59  79   9 105 106  10                                    
           20  3b  4f  09  69  6a  0a

# 7  
Old 03-18-2017
And, of course,
Code:
od -An -tu1 tmpchars | tr -s ' \n' ' '

will do the job ...
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question