0

I have some files in a directory "documents" (file1, file2, ...) and I would like to save them in another directory "documents_hex" with hexdump from command line. There is a way to use hexdump for each file in "documents" and save them in "documents_hex" ("documents_hex" is inside "documents") with the same name in input and output?

Example: file1 to /documents_hex/file1, file2 to /documents_hex/file2, ...

Eduardo Andrade
  • 111
  • 1
  • 1
  • 13
  • `cd documents; for file in *; do hexdump "$file" > "/path/to/documents_hex/$file"; done` -- unless your `hexdump` program has a `-o` option to specify the output, or something similar. (The `hexdump` on Cygwin doesn't have such an option.) – Jonathan Leffler Nov 21 '17 at 16:54
  • Thank you! One more doubt: I am using hexdump with -C option. There is a way to keep only the addresses and 16-bytes words? – Eduardo Andrade Nov 21 '17 at 17:25
  • I haven't spotted a way using just options to `hexdump`. You could use `hexdump -C "$file" | sed 's/[[:space:]]*|.*|$//' > "/path/to/documents_hex/$file"` in the body of the loop I suggested. This uses `sed` to delete the material between two bars, plus spaces immediately before that. – Jonathan Leffler Nov 21 '17 at 19:18

1 Answers1

0

Check this code :

for file in `ls documents`
do
  hexdump -x $file > documents_hex/$file
done
skr
  • 2,146
  • 19
  • 22