Differences

This shows you the differences between two versions of the page.

Link to this comparison view

array [2012/11/04 20:58] (current)
Line 1: Line 1:
 +@related: [[arpalhands]]  [[bash]]
 +
 +
 +<code type=bash>
 +#! /bin/bash
 +
 +function check_input
 +{
 +    nb=$(wc -c ${file_set2[0]} ${file_set2[*]} \
 + | awk '{print $1}' | sed '$d' | sort -u | wc -l)
 +    [ ${nb} != 1 ] && echo "Error: All input files must have same size !"
 +    [ ${nb} = 1 ]
 +}
 +
 +if [ ${#} -lt 3 ]
 +then
 +    cat << EOF
 +Usage: ${0##*/} element_size infile1 [ infile2 ... infileN ] outfile
 +element_size : size in bytes of element to read in each input files
 +EOF
 +    exit
 +fi
 +
 +element_size="${1}"
 +shift
 +file_set=("${@}")
 +idx=0
 +while [ 0${idx} -lt 0$((${#file_set[*]}-1)) ] ; do
 +    file_set2[idx]="$(mktemp)"
 +    xxd -c ${element_size} -p "${file_set[idx]}" > "${file_set2[idx]}"
 +    ((++idx))
 +done
 +check_input && paste -d '\n' ${file_set2[*]} \
 + | xxd -p -r > "${file_set[$((${#file_set[*]}-1))]}"
 +rm -f "${file_set2[*]}"
 +</code>
  
array.txt ยท Last modified: 2012/11/04 20:58 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki