I have a file that contains a long list of integers written in ascii separated with newlines, like such:-1752-19345345592-452355etc...I want to convert this file into a binary file containing the same integers, written as actual 4 byte integers.What command-line tool can I use to achieve this?
Convert file with integers written in ascii to binary file of integers
files;text processing;utilities;conversion;binary
perl -pe '$_=packl,$_' < infile > outfileUses the local endianness. Use l> instead of l for big-endian, and l< for little-endian.See perldoc -f pack for more info.Note that it's l as in lowercase L (for long integer), not the 1 digit.$ printf '%s\n' 1234 -2 | perl -pe '$_=packl,$_'| od -vtd40000000        1234          -20000010$ printf '%s\n' 1234 -2 | perl -pe '$_=packl>,$_'| od -vtx10000000 00 00 04 d2 ff ff ff fe0000010