Skip to content

Instantly share code, notes, and snippets.

@jopfre
Last active February 8, 2021 13:37
Show Gist options
  • Save jopfre/e69c75390791c1da82ad05466665dfba to your computer and use it in GitHub Desktop.
Save jopfre/e69c75390791c1da82ad05466665dfba to your computer and use it in GitHub Desktop.
for file in ./*.png;
do
if grep -q ${file:2} ./fileslist.txt;
then
echo "skipping $file"
else
echo "moving $file"
mv "$f" ./newdir
fi
done
while IFS="" read -r file || [ -n "$file" ]
do
printf '%s\n' "$file"
mv ./$file ./newdir/
done < fileslist.txt
# get list of files in current dir
printf '%s\n' *.png > current_dir_files.txt
# sort current dir files and files to exclude
sort current_dir_files.txt
sort filenames.txt
# save the filenames which exist in the current dir but not in the exclude list
comm -23 current_dir_files.txt filenames.txt > required_files.txt
# make newdir if it doesnt exist
mkdir -p ./newdir/
#loop through required files and move to newdir
while IFS="" read -r file || [ -n "$file" ]
do
printf '%s\n' "$file"
mv ./$file ./newdir/
done < required_files.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment