Skip to content

Instantly share code, notes, and snippets.

@aterga
Created February 24, 2020 16:00
Show Gist options
  • Select an option

  • Save aterga/9966e23bb0f4032c53cc7cb15b6c4443 to your computer and use it in GitHub Desktop.

Select an option

Save aterga/9966e23bb0f4032c53cc7cb15b6c4443 to your computer and use it in GitHub Desktop.
Move files that match pattern while preserving origin directory information
#!/bin/bash
####################################################################################
## Move files that match pattern while preserving origin directory information.
## Run as follows:
##
## find non-incremental/ -type f -name "*.smt2" -exec ./move.sh "forall" {} \;
##
####################################################################################
PATTERN=$1
FILE=$2
BASENAME="${FILE##*/}"
DIRNAME=${FILE%/*}
FILE_MINUS_EXT=${FILE%*.*}
EXT="smt2"
TARGET_DIR="with-$PATTERN"
DESTINATION=${FILE_MINUS_EXT//\./}
DESTINATION=${DESTINATION//\//__}
DESTINATION="$TARGET_DIR/$DESTINATION.$EXT"
if grep -q $PATTERN $FILE ; then
mkdir -p $TARGET_DIR;
echo Found interesting file $FILE;
mv $FILE $DESTINATION;
echo Moving to $DESTINATION;
else
echo Skipping file $FILE;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment