我正在Linux集群上工作。我有需要查找的文件列表。
Sample10
Sample22
这些文件还有另一个基于序列号的命名约定。制表符分隔的文件key.tsv
包含在单行中列出的两个名称。
Sample10 Serial102
Sample22 Serial120
我需要通过一个名称查找文件,然后使用其另一个(“序列”)名称将文件链接到另一个目录。这是我的尝试。
for i in "Sample10" "Sample22";
do
if [[ `find /directory/ -name $i*.fastq`]]
then
R1=$(find /directory/ -name $i*.fastq);
ln -s $R1 /output/directory/"$i".fastq;
else
echo "File existence failed"
fi
done
这可以从列表中找到感兴趣的文件并将其链接,但是我很困惑如何根据密钥中的条目重命名它们。
您可以通过调用来实现此目的find
,同时使用关联数组来保持从key.tsv文件读取映射信息:
#!/bin/bash
# build the hash for file mapping
declare -A file_map
while read -r src dst; do
file_map["$src.fastq"]=$dst # assume that the map doesn't have the .fastq extension
done < key.tsv
# loop through files and rename them
while read -d '' -r path; do # read the NUL separated output out find
base=${path##*/} # get the basename
dest=${file_map["$base"]} # look up the hash to get dest name
[[ $dest ]] || continue # skip if no mapping was found
echo "Creating a link for file $path"
ln -s "$path" "/dest/dir/$dest.fastq"
done < <(find /path/to/source/files -type f -name '*.fastq' -print0)
我还没有测试。将很乐意解决您可能发现的任何问题。
有关:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句