仅解压缩名称中包含与数字列表匹配的数字的某些文件
Unzip only certain files who's name contain a number that matches a list of numbers
我在一个目录中有大约 5530 个 zip 文件,它们都以特定的样式命名。例如:
monatswerte_RR_02076_19370101_19701230_hist.zip
现在我只想提取在 ~250 行长列表 (ids.txt) 的 5 位数字中 "RR_" 任何条目之后的 5 位模式匹配的文件。
我曾尝试使用 bash 脚本解决问题,但这不起作用:
for i in "ls"; do if [[$i ==*"cat ids.txt"*]]; then "unzip $i" fi; done
ids.txt的一些行:
~ » cat Dokumente/Schneehydro/historical/ids.txt
00013
00050
00085
00107
00108
...
05691
05804
05874
15574
bash
+ grep
解法:
for f in *_RR_[0-9]*.zip; do
num="${f#*_RR_}"
num=${num:0:5}
grep -qx "$num" ids.txt && unzip -q "$f"
done
我在一个目录中有大约 5530 个 zip 文件,它们都以特定的样式命名。例如:
monatswerte_RR_02076_19370101_19701230_hist.zip
现在我只想提取在 ~250 行长列表 (ids.txt) 的 5 位数字中 "RR_" 任何条目之后的 5 位模式匹配的文件。 我曾尝试使用 bash 脚本解决问题,但这不起作用:
for i in "ls"; do if [[$i ==*"cat ids.txt"*]]; then "unzip $i" fi; done
ids.txt的一些行:
~ » cat Dokumente/Schneehydro/historical/ids.txt 00013 00050 00085 00107 00108 ... 05691 05804 05874 15574
bash
+ grep
解法:
for f in *_RR_[0-9]*.zip; do
num="${f#*_RR_}"
num=${num:0:5}
grep -qx "$num" ids.txt && unzip -q "$f"
done