Skip to content

Instantly share code, notes, and snippets.

@sosoyososo
Last active March 10, 2016 03:22
Show Gist options
  • Save sosoyososo/24f1111784ed67e415aa to your computer and use it in GitHub Desktop.
Save sosoyososo/24f1111784ed67e415aa to your computer and use it in GitHub Desktop.
找出iOS代码工程里没有用到的图片
#! /bin/bash
#clear file content
echo '' > /tmp/png.txt
echo '' > /tmp/str.txt
#find all png image
for file in `find ./ -iname "*.png"`; do
result=`echo ${file} | grep -o "\.xcassets.*"`
if [[ ${result} == "" ]]
then
name=`echo "${file}" | grep -o "[^\/]*.png" | grep -o "[^\.@]*"`
echo "${name}" >> /tmp/png.txt
fi
done
sort -u /tmp/png.txt -o /tmp/png.txt
#find all string in .m .mm
for file in `find ./ -iname "*.m"`; do
if [ -r "${file}" ]
then
cat "${file}" | grep -o "\"[^\"]*\"" | tr -d '"' | grep -o "[^\.@]*" >> /tmp/str.txt
fi
done
for file in `find ./ -iname "*.mm"`; do
if [ -r "${file}" ]
then
cat "${file}" | grep -o "\"[^\"]*\"" | tr -d '"' | grep -o "[^\.@]*" >> /tmp/str.txt
fi
done
#find all image used in .xib .stroryboard
for file in `find ./ -iname "*.xib"`;do
if [ -r "${file}" ]
then
cat "${file}" | grep -o "image name=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | tr -d '"' | grep -o "[^\.@]*" >> /tmp/str.txt
fi
done
for file in `find ./ -iname "*.storyboard"`;do
if [ -r "${file}" ]
then
cat "${file}" | grep -o "image name=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | tr -d '"' | grep -o "[^\.@]*" >> /tmp/str.txt
fi
done
sort -u /tmp/str.txt -o /tmp/str.txt
#find string in png.txt but not in str.txt
awk 'NR==FNR{a[$0]}NR>FNR{ if(!($1 in a)) print $0}' /tmp/str.txt /tmp/png.txt
#remove file
rm /tmp/str.txt /tmp/png.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment