开发者

How to find all the php files under current directory and add a line

How do you do that in terminal or anywhere else?

echo "//test comment" > find . -type f -name "*.js"

doesn't wor开发者_如何学Gok. I just want to add a line on top of each .js files. Thanks.


#!/bin/bash
echo "//test comment" > myline
for file in *.js; do
  cp myline dummy
  cat $file >> dummy
  cp dummy $file
done 

or:

#!/bin/bash
for file in *.js; do
  sed -i '1i //test comment' $file
done 


Try something like this:

find . -type f -name "*.js" -exec echo >> {} \;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜