1 替换文件某一行
将文件./config/patchconfig/patch_config.json 的第二行替换为 "path": "../patchfiles",
将文件aaa.txt中的第三行替换为888
content='"path": "../patchfiles", ' sed -i "2c${content}" ./config/patchconfig/patch_config.json
sed -i '3c888' ./aaa.txt
2 替换某个字符
sed -i "s/;/GO/g" xxx.sql
3 awk 获取可执行文件名
#$NF为最后一列
which nginx | awk -F '/' '{print $NF}'
4 awk 显示除最后一列的所有列
awk '{$NF="" ;print $0}'
5 变量路径拆分
a='which nginx' ##### /usr/local/nginx/nginx echo ${a%/*} #### /usr/local/nginx/
5 获取文件所在目录
which nginx | xargs dirname
6 查找包含关键字的文件并拷贝到指定文件夹
find . -iname "*.json" |xargs grep redis |awk '{print $1}' |cut -d ":" -f 1 |xargs -i scp {} /newpath/ //(济南小老虎友情提供) https://www.cnblogs.com/jinanxiaolaohu/
7 sed 替换某一行
sed -i '7c "build": "ng build -c=production && xcopy .\\dist-rollup\\* %EnvPath%\\web\\apps\\fi\\gl\\web\\ /Y /D /R /K /F /S ",' .package.json
8 双引号处理
sed -ri "s#import { TreeTableModule } from x27@farris/ui-treetablex27;##g" .projectso-accountbalancefront-balanceinitsrcappalanceinitalanceinit.module.ts
参考:
https://blog.csdn.net/nanaranran/article/details/81203905
https://www.cnblogs.com/seasonzone/p/11274788.html
https://zhidao.baidu.com/question/878349927740895212.html
https://www.cnblogs.com/jinanxiaolaohu/
特殊符号对应16进制
|
x20 |