nanoparticlesims/growth_Melting_Silver_ICO_4091/dat_extractor

48 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
# Usage: ./script.sh "growthSims/run_*" output.txt
# The first argument is the directory pattern (e.g., growthSims/run_*)
# The second is the output filename
OUTPUT_FILE=$2
if [[ -z "$1" || -z "$2" ]]; then
echo "Usage: $0 \"pattern/run_*\" output_file"
exit 1
fi
# Write the header
echo "Natoms Edelta" > "$OUTPUT_FILE"
# The shell expands the wildcard into a list of arguments
# We loop through those arguments directly
for dir in $1; do
# Ensure we are looking at a directory
if [[ -d "$dir" ]]; then
echo "Processing $dir..."
# Check if energy.out exists inside the directory
# Using / to ensure pathing is correct
FILE_PATH="${dir}/energy.out"
if [[ -f "$FILE_PATH" ]]; then
# 1. Extract Natoms from the folder name
# This handles paths like 'growthSims/run_14' by taking the part after the last '_'
DIR_NAME=${dir%/}
NATOMS=${DIR_NAME##*_}
# 2. Extract the smallest Edelta (column 6)
MIN_EDELTA=$(grep -v '#' "$FILE_PATH" | awk '{print $6}' | sort -g | head -1)
# 3. Append to output file
if [[ -n "$MIN_EDELTA" ]]; then
echo "$NATOMS $MIN_EDELTA" >> "$OUTPUT_FILE"
fi
else
echo "Warning: $FILE_PATH not found, skipping..."
fi
fi
done
echo "Extraction complete. Results saved in $OUTPUT_FILE."