My hosting company requires me to put #!/usr/local/bin/ruby
at the top of every R开发者_JAVA百科B file. Is there an easy way to use sed recursively or something that can go through and append this to the top of every rb file?
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
to do it recursively, you can use find
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
精彩评论