2010-02-23 167 views

回答

2

AWK

$ awk 'NR==1{$0="#!/usr/local/bin/ruby\n"$0 }1' file > temp; mv temp file; 

sed的

sed -i.bak '1 i #!/usr/local/bin/ruby' file 

遞歸地做到這一點,你可以使用發現

find /path -type f -iname "*.rb" | while read -r FILE 
do 
    sed -i.bak '1 i #!/usr/local/bin/ruby' $FILE 
    # awk 'NR==1{$0="#!/usr/local/bin/ruby\n"$0 }1' >temp ; mv temp $FILe 
done 
相關問題