-1

Possible Duplicate:
How do I apply a shell command to many files in nested (and poorly escaped) subdirectories?

I am using this loop to remove empty lines in all files under given directories and sub directories. But it is not working

for file in /home/zubinan/public_html/src/Acme/*/*.php
do
sed '/^$/d' $file > tt
mv tt $file
done

It says Demo is a directory

4

4 回答 4

1

尝试这个;

for fname in `find /home/zubinan/public_html/src/Acme/ -type f`
do
    sed '/^$/d' $fname > tt
    mv tt $fname
done
于 2012-08-21T06:12:18.327 回答
0

如果要处理某个目录中的所有指定文件,可以使用这个 oneliner:

sed -i '/^$/d' `find /home/zubinan/public_html/src/Acme -name "*.php"`
于 2012-08-21T06:17:10.060 回答
0
for f in $(find /home/zubinan/public_html/src/Acme -type f \( -iname *.php \)); 
    do 
        relfilePath=${f:${#currentpath}:${#f}};
        // use  relfilePath here

    done
于 2012-08-21T06:31:06.440 回答
0

或试试这个:

 find /home/zubinan/public_html/src/Acme/ -type f -name "*.php" -exec sed -e '/^$/d' -i \{\} \;
于 2012-08-21T07:51:43.233 回答