我需要解压缩文件,并且对于该文件中的每个文档,我需要对注释进行更正(文件以C编写)。我对如何对文件中的每个文档执行此操作感到困惑(我不知道文档的数量或名称),是否可以在文件夹中编写for循环以打开每个文档单独编写文档,然后在shellscript中对其进行编辑?
我对sed和awk之间的区别也有点困惑,我应该在这里使用哪个。我需要编辑注释(以//开头),并认为我应该使用awk,但不太确定。
我到目前为止的伪代码就是这样
unzip $1
edit_comment(){
cat file1 file2 ... filen > total.txt
*some awk command that will search for all instances of // and replace the text on that line (after
the //) with a new comment*
}
谢谢!
答案 0 :(得分:0)
我相信您正在寻找How to do a recursive find/replace of a string with awk or sed。
假设:
-参数$1
是一些folder.tar.gz
或archive.zip
或blah.bz4
-该未压缩存档中包含注释的所有文件都应更改
dir=$(echo $1 | sed 's#\..*##')
find $dir -type f -print0 | xargs -0 sed -i 's#//old comment #//new comment#'