我正在尝试读取文件,并在 bash 中解析它。我需要做一个从todd
转换,然后循环并读取 X 字节,将每个 X 字节作为新文件中的一行进行管道传输:EBCDIC
ASCII
#!/bin/bash
# $1 = input file in EBCDIC
# $2 = row length
# $3 = output file
# convert to ASCII and replace NUL (^@) with ' '
dd conv=ascii if=$1 | sed 's/\x0/ /g' > $3.tmp
file=$(cat "$3.tmp")
sIndex=1
fIndex=$2
# remove file
rm $3
echo "filesize: ${#file}";
# loop, retrieving each fixed-size record and appending to a file
while true; do
# append record to file
echo "${file:sIndex:fIndex}" >> $3;
# break at end of file
if [ $fIndex -ge ${#file} ]
then
break;
fi
# increment index
sIndex=$((sIndex+fIndex));
done
# remove tmp
rm $3.tmp
有什么方法可以让整个过程更快?