请您尝试以下方法:
mapfile -t string < <(fold -w1 "string.txt")
# set string to an array of single characters: ("a" "b" "c" "d" ..)
while read -ra ary; do
if [[ ${ary[0]} = "position" ]]; then
# 1st line of file.vcf
declare -a pos=("${ary[@]:1}")
# now the array pos holds: (2 4 6 10 ..)
else
# 2nd line of file.vcf and after
declare -a new=("${string[@]}")
# make a copy of string to modify
for ((i=0; i<${#pos[@]}; i++ )); do
repl="${ary[$i+1]}" # replacement
if [[ $repl != "mis" && $repl != "het" ]]; then
new[${pos[$i]}-1]="$repl"
# modify the position with the replacement
fi
done
echo ">${ary[0]}"
(IFS=""; echo "${new[*]}")
# print the modified array as a concatenated string
fi
done < "file.vcf"
字符串.txt:
abcdefghijklmnop
文件.vcf:
position 2 4 6 10
name1 a b c d
name2 x y z a
name3 i mis k l
输出:
>name1
aacbecghidklmnop
>name2
axcyezghiaklmnop
>name3
aicdekghilklmnop
我已经尝试在上面的脚本中嵌入解释作为注释,但如果您仍有问题,请随时提问。
希望这可以帮助。