Tengo dos archivos de texto: string.txt y lengths.txt
String.txt:
abcdefghijklmnopqrstuvwxyz
lengths.txt
5
4
10
7
Quiero obtener el archivo
>Entry_1
abcde
>Entry_2
fghi
>Entry_3
jklmnopqrs
>Entry_4
tuvwxyz
Estoy trabajando con unas 28,000 entradas y varían entre 200 y 56,000 caracteres.
Por el momento, estoy usando:
start=1
end=0
i=0
while read read_l
do
let i=i+1
let end=end+read_l
echo -e ">Entry_$i" >>outfile.txt
echo "$(cut -c$start-$end String.txt)" >>outfile.txt
let start=start+read_l
echo $i
done <lengths.txt
Pero es muy ineficiente. ¿Alguna idea mejor?
{ while read l<&3; do head -c"$l"; echo; done 3<lengths.txt; } <String.txt.
str="$(cat string.txt)"; i=0; while read j; do echo "${file:$i:$j}"; i=$((i+j)); done <length.txtparece lo suficientemente rápido como lo hace solo por shell ..