I have a two text files: string.txt and lengths.txt
String.txt:
abcdefghijklmnopqrstuvwxyz
lengths.txt
5
4
10
7
I want to get the file
>Entry_1
abcde
>Entry_2
fghi
>Entry_3
jklmnopqrs
>Entry_4
tuvwxyz
I'm working with about 28,000 entries and they vary between 200 and 56,000 characters.
At the moment, I'm using:
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
But it's very inefficient. Any better ideas?
str="$(cat string.txt)"; i=0; while read j; do echo "${file:$i:$j}"; i=$((i+j)); done <length.txt
..seems fast enough as done only by shell.. – heemayl Aug 12 '15 at 11:30{ while read l<&3; do head -c"$l"; echo; done 3<lengths.txt; } <String.txt
. – jimmij Aug 12 '15 at 11:58