这是下载的数据:
这是我想要的结果:以样本名命名文件夹(3521-SR-2) 链接三个文件:
3219-SR-1
barcodes.tsv.gz
features.tsv.gz
matrix.mtx.gz
这里的步骤关键是如何批量提取文件中的样本名字,以下是我的提示语 让ai给我生成bash命令批量完成:
点击链接查看对话详情:
https://www.doubao.com/thread/w19bbe94b644bac3d
给我的命令:
#!/bin/bash# 遍历当前目录下所有以 GSM 开头的文件
for file in GSM*; do
# 提取 _ 到最后一个数字的内容
identifier=$(echo "$file" | sed 's/.*_\([^_]*[0-9]\).*/\1/')
if [ -n "$identifier" ]; then
# 创建对应的文件夹,若文件夹已存在则不报错
mkdir -p "$identifier"
# 根据文件后缀判断文件类型并进行链接
if [[ $file == *barcodes.tsv.gz ]]; then
ln -s "$(realpath "$file")" "$identifier/barcodes.tsv.gz"
elif [[ $file == *features.tsv.gz ]]; then
ln -s "$(realpath "$file")" "$identifier/features.tsv.gz"
elif [[ $file == *matrix.mtx.gz ]]; then
ln -s "$(realpath "$file")" "$identifier/matrix.mtx.gz"
fi
fi
done
完美解决问题,AI真的不错,大家快来试试吧;
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!