Last active
June 6, 2017 19:47
-
-
Save codingbychanche/88f32baa0c52cadf1b6ac160763dd1d0 to your computer and use it in GitHub Desktop.
Bash Scripts
This file contains 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
# This checks for a string in a file | |
search='sawfish' | |
file='maze.atr' | |
if [ $(strings $file | grep -i $search) ] | |
then | |
echo $search found in file $file | |
else | |
echo $search not found in file $file ! | |
fi |
This file contains 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
# Search file names, save the matching results to | |
# a file ('result') and copy found files to a folder | |
# Result already there? If so, delete it | |
if [ $(find . -name "result") ] | |
then | |
echo Deleting existing result.... | |
rm result | |
else | |
echo New result file will be created.... | |
fi | |
# Search | |
find ~/ -name "*.atr" > result | |
# Make destination folder | |
mkdir filesFound | |
# Read result line by line and copy found files to destination.... | |
files=0 | |
while read result | |
do | |
let "files=files+1" | |
echo Files $files: Copying "$result".... | |
cp "$result" filesFound | |
done < result | |
echo Done! $files found and copied.... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment