#!/bin/bash LEN=0 RECID=1 if ! [ -f phonebook.txt ] then echo "File phonebook.txt not found" exit 1 fi # LE BOM: 0xFF 0xFE # record ID (starts at 1) # name # reserved # phone number 1 # phone number 2 # phone number 3 # phone number 4 # phone number 5 # reserved # line break printf "\xff\xfe" # Set IFS to tab, newline IFS=$'\t\n' while read NAME NUMBER do LEN=$( echo -n "${NAME}" | wc -c ) if [ $LEN -gt 24 ] then echo "Line ${RECID} too long" 1>&2 exit 1 fi #echo -e "${RECID}\t${NAME}\tRes\t${NUMBER}\tPhNr2\tPhNr3\tPhNr4\tPhNr5\tRes\r" | iconv -f UTF-8// -t UTF-16LE// echo -e "${RECID}\t${NAME}\t\t${NUMBER}\t\t\t\t\t\r" | iconv -f UTF-8// -t UTF-16LE// let RECID+=1 done < "phonebook.txt" # Restore IFS IFS=$' \t\n'