strutture:roma1:experiments:ams2:internal_note_naia:bash_script
#!/bin/bash # Directory path where .root files are located DIR="/storage/gpfs_ams/ams/groups/AMS-Italy/ntuples/v1.1.0/ISS.B1236/pass8" # Output file path (explicitly in current directory) OUTPUT="$(pwd)/file_list.txt" # Minimum and maximum Unix timestamps for filtering MIN_TIME=1640994629 MAX_TIME=1646093960 # Debug: Show current directory and permissions echo "Current directory: $(pwd)" echo "Permissions of current directory: $(ls -ld .)" # Remove the output file if it already exists echo "Removing $OUTPUT if it exists..." rm -f "$OUTPUT" || { echo "Error: Cannot remove $OUTPUT, check permissions"; exit 1; } # Test write permission echo "Testing write permission in $(pwd)..." touch "$OUTPUT" || { echo "Error: Cannot create $OUTPUT, no write permission"; exit 1; } rm -f "$OUTPUT" # Change to the input directory echo "Changing to $DIR..." cd "$DIR" || { echo "Error: Cannot change to $DIR"; exit 1; } # Use ls and awk to filter and sort files in one go echo "Generating $OUTPUT..." ls -1 *.root | awk -v dir="$DIR" -v min="$MIN_TIME" -v max="$MAX_TIME" ' { # Extract timestamp by removing .root extension timestamp = substr($0, 1, length($0)-5) # Check if timestamp is numeric and within range if (timestamp ~ /^[0-9]+$/ && timestamp > min && timestamp < max) { print dir "/" $0 } }' | sort -n > "$OUTPUT" || { echo "Error: Cannot write to $OUTPUT during sort"; exit 1; } # Count the number of lines in the output file count=$(wc -l < "$OUTPUT") # Print completion message echo "File $OUTPUT created successfully with $count entries."
strutture/roma1/experiments/ams2/internal_note_naia/bash_script.txt · Last modified: 2025/05/02 13:56 by bartolon@infn.it