gpt4 book ai didi

excel - bash 脚本 : end of line character issue : file from excel

转载 作者:行者123 更新时间:2023-12-04 20:20:06 28 4
gpt4 key购买 nike

在 Linux ubuntu 10 下使用 bash 工作

我有 Bash 脚本,它从 gedit 创建的 .txt 文件中读取行,然后将其推送到一个数组中。按预期工作。

但是,当我的输入是从 Excel 生成的 .txt 时,它会引发错误

")syntax error: invalid arithmetic operator (error token is "

echo -n $elem | od -x yields
0000000 3533 0d32
0000004

我情不自禁地觉得自己快要解决了,但它却让我望而却步,这让我很沮丧。我会很感激一些帮助

谢谢

@MarcB
来自 excel 的文件:(从 gedit 剪切'n'粘贴;与外观相反,此文件中没有空行;而是行交替 int、str、int、str ...)
0

A?GATCGGAAGAGCGTCGTGTAGGGAAAGAGTGTAGATC
1

A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACATCACGAT[AC]T

2

A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACCGATGTAT[AC]T

3

A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACTTAGGCAT[AC]T

4

A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACTGACCAAT[AC]T

5

A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACACAGTGAT[AC]T

6

A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACGCCAATAT[AC]T

7

A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACCAGATCAT[AC]T

8

A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACACTTGAAT[AC]T

9

A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACGATCAGAT[AC]T

10

A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACTAGCTTAT[AC]T
rtstxt='readthrusequences.txt'

# establish readthrusequence array ---------------------------------------------
# push into sparse array the readthru adapter sequence for each TruSeq index
# use the TruSeq Index number as key to the sequence
forts=${pathsir}${rtstxt} # FileOf ReadThruSequences
rts=( $(cat ${forts}) )

idx=""
elem=""
isIdx=1
for elem in ${rts[@]}; do
echo '$elem:'${elem}
# echo 'elem:' ${elem} 'before IF - isIdx:' $isIdx '- idx:' $idx
if [[ $isIdx = 1 ]]; then
echo ' 1_block - $isIdx:'$isIdx' - elem:'$elem' - idx:'$idx;
indexseq[$elem]=0;
#echo " indexseq[elem] set to ${indexseq[$elem]}";
idx=$elem;
#echo " idx set to elem (i.e. $idx)";
isIdx=0;
#echo " isIdx reset to $isIdx";
#echo " " ;
else
#echo " 2_block - isIdx:$isIdx - elem:$elem - idx:$idx";
indexseq[$idx]=$elem;
#echo " indexseq[idx] set to ${indexseq[$idx]}";
isIdx="1"; idx="0";
#echo " isIdx reset to $isIdx - idx reset to $idx";
#echo "";
fi
# echo "keys (TruSeq index): ${!indexseq[*]}"
# echo "vals (indexed adapter seq): ${indexseq[*]}"
done

此代码将文件内容推送到数组中,使用 int 作为索引,使用 str 和值。

注释行是调试。如果第一个未注释,则控制台产生
before IF - isIdx: 1 - idx:
- idx:k - $isIdx:1 - elem:0
")syntax error: invalid arithmetic operator (error token is "

明确指出行尾问题;但是我在这堵墙上撞了太久了,还没有找到解决办法。我知道有一个简单的...

最佳答案

一个 excel 生成的文件几乎肯定会使用\r\n 字符对来终止每一行。 (文件末尾可能有一个 Ctrl-Z 字符)。基于 Unix 的系统只期望\n 字符来终止输入行(并且 Ctrl-D(通常不)作为文件结束标记)。

解决方案,要么编辑文件以删除每行末尾的 ^M 字符(\r)(还要检查文件末尾的 ^Z 并删除它),或者标准是

 dos2unix file file2 .... filen

我希望这有帮助。

关于excel - bash 脚本 : end of line character issue : file from excel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8138148/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com