我有一个文件,我必须遍历几次,每次都用 python 运行它。如何从 shell 中的特定行中删除或添加字符?
以ex.file为例,
$ cat ex.file
stuff
more stuff
more stuff
more stuff
#<- remove this character
<-add a pund sign here
more stuff
more stuff
我想要的输出是:
$ cat ex.file
stuff
more stuff
more stuff
more stuff
<- remove this character
#<-add a pund sign here
more stuff
more stuff
最佳答案
在第 6 行的开头添加#:
sed '6 s/^/#/' ex.file
从第 5 行删除前导#:
sed '5 s/^#//' ex.file
关于bash - 如何在 shell 中的指定行号中添加或删除字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38864538/