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
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论