手動(dòng)修改——當(dāng)我沒說……
用腳本去解決,之前我用perl寫過這樣功能的腳本,但是時(shí)間久遠(yuǎn),我已經(jīng)找不到了。
簡(jiǎn)單分析一下,大概是一下幾步
以上就簡(jiǎn)單處理了大部分的情況,就此打住,腳本么,簡(jiǎn)簡(jiǎn)單單的處理個(gè)七七八八就可以了。能處理的就要處理對(duì),不能處理的就記錄下來(lái)。
根據(jù)以往的經(jīng)驗(yàn),在一個(gè)大而復(fù)雜的系統(tǒng)里面,這樣的結(jié)果可能會(huì)出現(xiàn)找到多個(gè)的很多,這樣就會(huì)很麻煩,但也沒辦法。
一下是shell腳本,經(jīng)測(cè)試,能工作。
#!/bin/bash
workdir=.
modify=0while [ $# -gt 0 ]
do case $1 in "--modify")
modify=1
;;
"--work-dir")
shift
workdir=$1
;;
*)
echo "USAGE: $0 [--work-dir ] [--modify] [--help]"
exit1 esac shiftdoneecho "work-dir: $workdir, modify: $modify"
h_files=$(tempfile)
none_files=files_none
ok_files=files_one
more_files=files_more
>$none_files
>$ok_files
>$more_files
all_find=$(tempfile)
deal_files=$(tempfile)
grep -Prsh '^s*#s*include' $workdir | grep -Po 'w+.h' | sort | uniq | while read hfile
do echo -n .
if [ $(find $workdir -name "$hfile" | wc -l) -eq 0 ]
then find $workdir -iname "$hfile" > $all_find
cat $all_find | grep -Po 'w+.h$' | sort | uniq > $h_files
file_cnt=$(cat $h_files | wc -l)
if [ $file_cnt -eq 0 ]
then echo $hfile >> $none_files
elif [ $file_cnt -eq 1 ]
then
newfile=$(cat $h_files)
echo $hfile '->' $newfile >> $ok_files
cat $all_find >> $ok_files
#for ok, deal it
if [ $modify -eq 1 ]
then grep -Prsn "^s*#s*include.*$hfile" $workdir > $deal_files
if [ $(cat $deal_files | wc -l) -gt 0 ]
then cat $deal_files | awk -F: '{print $1}' | xargs perl -i -pe "s/$hfile/$newfile/" echo modified: >> $ok_files
cat $deal_files >> $ok_files
fi fi else echo -- $hfile -- >> $more_files
cat $all_find >> $more_files
fi fidoneecho Done!
echo the result in file: $none_files, $ok_files and $more_files