You want newlines. So output newlines.
while read in; do sigtool --hex-dump "$in"; echo; done < file.txt > test.txt
Note the added echo
command.
Mind you, the first place I would check is the sigtool
man page to see if there's an option to output trailing newlines.
Okay, I wrote the above without actually getting sigtool
(from the clamav
package) and testing it. Now I have done so.
The code you wrote doesn't work, at least not with clamav-0.99.2-3.el6.x86_64. sigtool
accepts input on its standard input. It has no option to accept and translate command line arguments.
So what you really want is, dropping back to the old favorite non-visual editor ex
:
printf '%s\n' 'g/^/.!tr -d \\n | sigtool --hex-dump' %p | ex file.txt > test.txt
Demonstration:
$ cat file.txt
string1
string2
string3
$ printf '%s\n' 'g/^/.!tr -d \\n | sigtool --hex-dump' %p | ex file.txt > test.txt
$ cat test.txt
737472696e6731
737472696e6732
737472696e6733
$
Explanation:
Globally (for each line matching regex /^/
, which is every line) filter each line (.!
) through the shell pipeline tr -d \\n | sigtool --hex-dump
, then print (p
) the entire buffer (%
) to standard output, and don't save changes to file.txt
.
Another approach, using Awk:
awk -v p='sigtool --hex-dump' '
{printf "%s", $0 | p; close(p); printf "\n"}
' file.txt > test.txt
737472696e6731a737472696e6732a737472696e6733
, it will print in one line, with a space.while read in; do echo -e "$(sigtool --hex-dump "$in")\n"; done < file.txt > test.txt
?sigtool
for this? have you considered something likeperl -lpe '$_ = unpack("H*",$_)' file.txt
instead?xxd
, which can do conversions in either direction?