开发者

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

开发者 https://www.devze.com 2023-04-10 02:30 出处:网络
How do you do that in terminal or anywhere else? echo \"//test comment\" > find . -type f -name \"*.js\"

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

精彩评论

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

关注公众号