Created
February 24, 2020 16:00
-
-
Save aterga/9966e23bb0f4032c53cc7cb15b6c4443 to your computer and use it in GitHub Desktop.
Move files that match pattern while preserving origin directory information
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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