wolbo

在文件开始追加一行 

1 使用sed(会改变文件编码为utf-8)

 find -name "*.cpp" -exec sed -i \'1s@^@added line\n@\' {} \;

#sed insert append
#第一行行前插入一行
sed -i \'1i added line\' main.cpp
#最后一行行前插入一行
sed \'$i 添加的内容\' file 
#最后一行行后添加一行   
sed \'$a添加的内容\' file   

2 编写shell脚本

files=`find -name \'*.cpp\'`
for file in ${files}
    do
        echo \'#include"pch.h"\' | cat - ${file} > ${file}_temp && mv ${file}_temp ${file}
    done

 

 

 

 

 

参考:

1 https://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/

2 https://www.cnblogs.com/lgj8/p/12490863.html

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-02
  • 2022-12-23
  • 2021-07-27
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-02
  • 2021-10-29
  • 2021-08-12
  • 2021-10-11
  • 2022-01-28
  • 2022-02-09
相关资源
相似解决方案