csh - 如何在csh中的2个字符串之间更改字符串?
问题描述
我有如下输入文件,我希望在set xx { \
&之间替换字符串,}
如输出所示。如何在 csh 中编码?
输入:
set a 1
set b 2
set xx { \
a/c/d \
apple/d/e/g \
guava/s/s/g/b/c \
}
set c 3
输出:
set a 1
set b 2
set xx { \
a/*c*/d* \
apple/d/*e*/g* \
guava/s/s/g/*b*/c* \
}
set c 3
解决方案
$ cat fixer.sed
#!/bin/sed -f
/set xx {/ , /}/ {
s@\(/.*\)\([^/]\)\(/[^/]*\)\( *[\]\)$@\1*\2*\3*\4@
}
/set xx {/ , /}/
是一个范围表达式,sed
扫描每一行,但只s@...@...@
对提供的范围之间的行执行操作。
$ chmod +x fixer.sed # only the first time you create file
输出
$ ./fixer.sed txt.txt
set a 1
set b 2
set xx { \
a/*c*/d* \
apple/d/*e*/g* \
guava/s/s/g/*b*/c* \
}
set c 3
推荐阅读
- javascript - 从 Java 后端下载带有 Angular 前端的文件
- java - 使用多部分/混合的放心的音频文件上传
- javascript - python 2.7 或 javascript:使用具有身份验证的下载链接下载文件
- java - OSMdroid:zoomToBoundingBox 缩放到错误的边界框
- python - sqlite - 如何通过整数值根据概率选择行?
- javafx - JavaFX TextFlow 滚动条
- hadoop - YARN Dr.who Application Attempt appattempt 失败
- objective-c - Objective-C 顺序执行两个完成块
- php - Wordpress,wp_mail 发送两次
- angularjs - 禁止 (403) CSRF 验证失败。请求中止。Django + AngularJS