I'm dealing with a rather peculiar issue. I want to catch all file names in a directory that contain a range of numbers. The directory has the following files
run_1_500ns.root
run_2_500ns.root
run_3_500ns.root
run_4_500ns.root
run_5_500ns.root
...
run_55000_500ns.root
For instance I want to get the files run_600_500ns.root
and run_601_500ns.root
and feed them in the hadd
command (that's a command from the ROOT/cern data analysis software).
If I run the following command on a terminal I get the filename that I'm looking for.
$ filename=`find . -name "*_600_*.root" | sed 's#.*/##'`
$ echo filename
run_600_500ns.root
However, if I run the following script, I get all files in the directory.
This script used to work on redHat 6
but at the moment I'm using Ubuntu 18.04
. Not sure if that's the issue, but it's the only (big) change in my setup. Any idea on what might be the issue?
#!/bin/bash
# A script to add root files using hadd command
# NOT idiot proof
#variables
CURRENT_DIR=$(pwd)
echo
if [ "$#" -eq 4 ]; then
#input arguments
OUT_ROOT=$(readlink -f $1)
FILES_DIR=$(readlink -f $2)
FIRST_RUN=$3
LAST_RUN=$4
echo
echo "Output file : $OUT_ROOT"
echo "Input files : $FILES_DIR"
echo
cd $FILES_DIR
#source_root_files="*"`seq -s "*.root *" $FIRST_RUN $LAST_RUN`"*.root"
source_root_files=""
filename=""
for i in $(seq $FIRST_RUN $LAST_RUN); do
filename=$(find . -name "*_$i_*.root" | sed 's#.*/##')
source_root_files="$source_root_files $filename"
done
echo "Merging root files"
hadd -f6 $OUT_ROOT $source_root_files
cd $CURRENT_DIR
else
echo "Provide the correct number of arguments"
echo "Usage : radd.sh <output root file> <input root file directory> <first run> <last run>"
fi
Running the script as sh -x script.sh 2> log.log
gives me the following
+ pwd
+ CURRENT_DIR=current_directory
+ echo
+ [ 4 -eq 4 ]
+ readlink -f test.root
+ OUT_ROOT=current_directory/test.root
+ readlink -f .
+ FILES_DIR=current_directory
+ FIRST_RUN=600
+ LAST_RUN=601
+ echo
+ echo Output file : current_directory/test.root
+ echo Input files : current_directory
+ echo
+ cd current_directory
+ source_root_files=
+ filename=
+ seq 600 601
+ find . -name *_*.root
+ sed s#.*/##
+ filename=S0Test_51686_500ns_CW_0ns_CBT_0ns_DEBT.root