1

I have these files in the same folder:

results1_1_2_4
results2_1_2_4
results3_1_2_4
results4_1_2_4
results5_1_2_4

results1_0.001_2_25
results2_0.001_2_25
results3_0.001_2_25
results4_0.001_2_25
results5_0.001_2_25

results1_0.1_3_50
results2_0.1_3_50
results3_0.1_3_50
results4_0.1_3_50
results5_0.1_3_50

I would like to combine the five files results1+results2+results3+results4+results5 for each combination, for example "1_2_4", "0.001_2_25" and "0.1_3_50". So the ouput should be:

results_1_2_4
results_0.001_2_25
results_0.1_3_50

A similar question is here (cat multiple files based on ID in filename), but I tried with no success:

for f in results*; do cat "$f" >> "results${*_f%%}"; done
4

1 回答 1

3

只是稍微调整一下参数扩展:

for f in results*; do
  cat "$f" >> "results_${f#*_}"
done
于 2020-05-29T19:02:26.987 回答