#!/bin/bash
read -p 'input key:' key
read -p 'input new key:' new_key
if [[ ! -d "jar_temp" ]];then
mkdir jar_temp
fi
#rm -rf jar_temp/*
find ./ -name "*.jar">jar_list.txt
cat jar_list.txt|while read li
do
rm -rf jar_temp/*
this_dir_name=${li%/*}
this_file_name=${li##*/}
echo this file name is :$li
cp $li ./jar_temp
cd ./jar_temp
jar -xvf $this_file_name
rm -f $this_file_name
find ./ -type f | xargs -i sed -i 's/'$key'/'$new_key'/g' {}
jar cvf0M $this_file_name ./*
echo "dir name is" :$this_dir_name
cd ..
mv -b ./jar_temp/$this_file_name $this_dir_name
done
rm -f jar_list.txt
version2.0
#!/bin/bash
read -p 'input key:' key
read -p 'input new key:' new_key
if [[ ! -d "jar_temp" ]];then
mkdir jar_temp
fi
if [[ -f "find_jar.txt" ]];then
rm -f find_jar.txt
fi
find ./ -name "*.jar">jar_list.txt
cat jar_list.txt|while read li
do
rm -rf jar_temp/*
this_dir_name=${li%/*}
this_file_name=${li##*/}
#echo this file name is :$li
cp $li ./jar_temp
cd ./jar_temp
jar xvf $this_file_name
rm -f $this_file_name
#find ./ -type f | xargs -i sed -i 's/'$key'/'$new_key'/g' {}
#jar cvf0M $this_file_name ./*
find ./ -type f |grep -v "this_jar_list.txt"> this_jar_list.txt
cat this_jar_list.txt
count=0
for this_li in `cat this_jar_list.txt`
do
result=`cat $this_li|grep "$key"`
if [[ $result ]];then
((++count))
echo $count
fi
done
echo 'sum of files :' $count
if [ "$count" -eq "0" ];then
cd ../
continue
fi
rm -f this_jar_list.txt
find ./ -type f | xargs -i sed -i 's/'$key'/'$new_key'/g' {}
jar cvf $this_file_name ./*
cd ../
echo "file name is :" $li
echo $li>>find_jar.txt
mv -b ./jar_temp/$this_file_name $this_dir_name
done
rm -f jar_list.txt
网友评论