sed -n用文件扩展名'n'创建一个新文件

时间:2019-04-25 16:28:18

标签: linux bash sed

Linux:RHEL6.10圣地亚哥

当我将sed-n(用于静默模式)一起使用时,它适用于原始文件,但是为什么最终使用以下命令创建新文件:对文件没有影响,并且文件扩展名中带有相同名称+后缀字符n,请参见下文-文件:/tmp/11.txtn

   -n, --quiet, --silent
          suppress automatic printing of pattern space

这里

[myuser@rhel6linuxserverl15 a_folder]$ cat /tmp/11.txt 
arun nuka
arun snooka
arun chinga
arun patinga

[myuser@rhel6linuxserverl15 a_folder]$ sed -i "/arun snooka/ d" /tmp/11.txt 
[myuser@rhel6linuxserverl15 a_folder]$ cat /tmp/11.txt 
arun nuka
arun chinga
arun patinga

[myuser@rhel6linuxserverl15 a_folder]$ sed -in "/arun chinga/ d" /tmp/11.txt 
[myuser@rhel6linuxserverl15 a_folder]$ 
[myuser@rhel6linuxserverl15 a_folder]$ cat /tmp/11.txt
arun nuka
arun patinga

[myuser@rhel6linuxserverl15 a_folder]$ ls -l /tmp/11*
-rw-r--r-- 1 myuser grpup1 24 Apr 25 16:19 /tmp/11.txt
-rw-r--r-- 1 myuser grpup1 36 Apr 25 16:19 /tmp/11.txtn
[myuser@rhel6linuxserverl15 a_folder]$ cat /tmp/11.txtn 
arun nuka
arun chinga
arun patinga

[myuser@rhel6linuxserverl15 a_folder]$ 

2 个答案:

答案 0 :(得分:4)

-i采用可选参数,该参数表示备份文件的扩展名。使用-n -i或指定扩展名(-n -i~是常见的)。

  

-i [SUFFIX],--in-place [= SUFFIX]

     

编辑文件到位(如果提供SUFFIX,则进行备份)

答案 1 :(得分:2)

调用sed -in时,没有传递参数-n。相反,您将n作为备份文件的后缀传递到-i

-i extension
         Edit files in-place, saving backups with the specified extension.  If a zero-length extension is given, no backup will be saved.  It is not recommended to give a zero-length extension when in-place editing files, as you risk corruption or
         partial content in situations where disk space is exhausted, etc.