檢查文件是否存在
cat list | while read line
do
arr=(${line//\\t/ })
mkdir ${arr[0]}"~" && cd ${arr[0]}"~"
filename="work_"${arr[0]}".sh"
cat>"${filename}"<<EOF
cat ../${arr[0]} | while read line
do
ar=(\${line//\\\t/ })
file=\${ar[1]}
#record=${arr[0]}"_rd"
if [ -f \$file ];then
echo "True" >> record
else
echo "False" >> record
fi
paste ../${arr[0]} record > ${arr[0]}"_0207"
done
EOF
qsub -cwd -l vf=1g,num_proc=1 -q st.q -P P20Z10200N0059 -binding linear:4 $filename
cd ../
done
同步文件命令
rsync -acvotglp SourcePath TargetPath
創(chuàng)建數(shù)組和模糊搜索文件
line='col1 col2 col3 col4'
arr=(${line//\\t/ })
mkdir ${arr[0]} && cd ${arr[0]}
name=${arr[0]}
cdna=${arr[1]}
oligo=${arr[2]}
output=${arr[3]}
cdnaf1=$(find $cdna |xargs ls -Rd | grep 1.fq.gz)
cdnaf2=$(find $cdna |xargs ls -Rd | grep 2.fq.gz)
標(biāo)準(zhǔn)打印內(nèi)容到指定文件
name='test'
filename="work_"$name".sh"
cat>"${filename}"<<EOF
Rscript "creat_input_"$name".R"
EOF
也可以直接使用echo
echo "Rscript creat_input_${name}.R" > "${filename}"
交互輸入?yún)?shù)
read -p "Please enter a target directory or enter with nothing(current directory) :" dir
cat $1 | while read line
do
echo $1
done
根據(jù)文本生成報(bào)告
rm -rf *$1*
cat datasets_list | while read line
do
arr=(${line//\\t/ })
name=${arr[0]}
path=${arr[1]}
cat $path/$name/07.report/$1| cut -d ',' -f 2 |tr "\n" ","|xargs -I {} echo ${name}","{} >> $1\.xls
done
sed -i 's/,/\t/g' $1\.xls
cat 07.report/$1|cut -d ',' -f 1|tr "\n" ","|xargs -I {} echo ${name}","{}|sed 's/ /_/g'|sed 's/,/\t/g' > header_$1\.txt
cat header_$1\.txt $1\.xls > $1\_overall.xls
簡(jiǎn)易for循環(huán)
for i in A B C D E F G all ;
do
echo $i
done
Job_progress
read -p "Please enter a target directory or enter with nothing(current directory) :" dir
if [ ! $dir];then
dir=$(echo $PWD)
fi
echo you have entered $dir
aimdir=`find $dir -maxdepth 2 -type d | grep \\\-*\\- `
num=0
done=0
err=0
undo=0
run=0
dat=`date '+%D'|sed -e s/[/]/_/g`
rm -rf *_list_$dat
mkdir -p "00.stat_list_"$dat;cd "00.stat_list_"$dat
for i in ${aimdir}
do
#Total tasks: num+undo
if [ -d ${i}/*2.fq.gz ]; then
num=$(($num+1))
else
undo=$(($undo+1))
echo -e "\033[31;1m NOTE!!! $i STATE: \t UNDO \033[0m"
echo $i >> undo_list_$dat
fi
#Done tasks
if [ -f ${i}/*2.fq.gz ]; then
done=$(($done+1))
echo $i >> done_list_$dat
fi
#Error tasks and running tasks
fl=$(ls -lh ${i} |grep .sh.e|grep " 0 ")
if [ "$fl" = "" ]; then
err=$(($err+1))
echo $i >> error_list_$dat
echo -e "\033[31;1m NOTE!!! $i STATE: \t ERROR \033[0m"
else
if [ -d ${i}/*2.fq.gz ]; then
if [ ! -f ${i}/*2.fq.gz ]; then
run=$(($run+1))
echo $i >> run_list_$dat
fi
fi
fi
done
echo -e "\t\033[0mTotal tasks: \t\t $((num+undo)) \n\tSTATE:\033[29;1m \t\t Sample Count "
echo -e "\tUNDO:\033[31;1m \t\t ---Undo tasks--- \t ${undo} \033[0m"
echo -e "\tERROR:\033[31;1m \t\t +++Error tasks+++ \t ${err} \033[0m"
echo -e "\tRUNNING:\033[34;1m \t ===Running tasks=== \t ${run} \033[0m"
echo -e "\tDONE:\033[32;1m \t\t ***Done tasks*** \t ${done} \033[0m"
遞歸統(tǒng)計(jì)文件內(nèi)存
declare -a array=()
while read line
do
#echo $line
array[${#array[*]}]=$line
done < $1
echo "du -sh ${array[*]}"