这是我的代码:
#!/bin/bash
for file1 in
/net/zmf8/cb/37/lxy161830/work/target_readcount/*.readcount.txt;
do
for file2 in /net/zmf8/cb/37/lxy161830/work/nontarget_readcount/*.nontargetreawdcount.txt;
if [ $( basename${file1:0:1} ) == $( basename${file2:0:1} ) ];then
cat $file1 $file2 > '*.readcount.txt'
fi
done
但我只是不知道如何仅比较两个文件名的“*”部分。它总是回复
./integrate.sh: line 5: syntax error near unexpected token `if'
./integrate.sh: line 5: ` if [ $( basename${file1:0:1} ) == $(basename${file2:0:1} ) ];then'
您的内循环需要自己的
do
和 done
。我建议对此进行编辑。
如果您只是想跳过将同一文件与其自身进行比较,您可以尝试以下操作:
case $file1 in
$file2) continue;;
esac
尽管我读到它,文件名(甚至只是基本名称)永远不会冲突。
由于点的原因,
*.nontargetreadcount.txt
永远不会匹配*.readcount.txt
。
另外,我认为您不希望在输出文件名中包含
*
。也许类似
cat $file1 $file2 > /tmp/$( basename $file1 ).$( basename $file2 )