Last active
February 3, 2017 11:22
-
-
Save Christian-G/93237c0607bb45fdabb724dda160659e to your computer and use it in GitHub Desktop.
grep & sed
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
# find non UTF8 encoded files | |
find . -type 'f' -exec file {} \; | grep 'ASCII' | |
# find | |
grep -rnw 'app/views/bids' -e "pandoc" | |
# fix | |
find '20' -type f -exec gsed -i.bak "s/test/\/media\/Telecom Italia/g" {} \; | |
find '21' -type f -exec gsed -i.bak "s/Telecom Italia (AWS)\/pandoc-output\/media/\/media\/Telecom Italia (AWS)/g" {} \; | |
find 'app/views/bids/8' -type f -exec gsed -i.bak "s/Dom-Daniel \/media\/LLC/\/media\/Dom-Daniel LLC/g" {} \; | |
# rename uppercase to lowercase file extension | |
find . -name '*.*' -exec sh -c 'a=$(echo "$0" | gsed -r "s/([^.]*)\$/\L\1/"); [ "$a" != "$0" ] && mv "$0" "$a" ' {} \; | |
# Check for file references and see if filex actually exists | |
grep -ro 'app/views/bids/' -e "(\/media.*)" | sed 's/\/media/public\/media/g' | sed 's/.*://g' | sed 's/[()]//g' | xargs find | |
# Check for file references and see if filex actually exists #2 | |
grep -ro 'app/views/bids/' -e "(\/media.*)" | sed 's/\/media/public\/media/g' | sed 's/.*://g' | sed 's/^(//g' | sed 's/)$//g' | while read f; do file "$f"; done | grep "cannot open" > 404s.txt | |
# Find files with names _23 - _34 and create backup | |
find 'app/views/bids' -type f -name "_2[3-9]*" -o -name "_3[0-9]*" | xargs tar rvf bids_not_yet_needed.tar | |
# Remove files with names _23 - _34 | |
find 'app/views/bids' -type f -name "_2[3-9]*" -delete -o -name "_3[0-9]*" -delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Brackets mean "any one of".