Reputation: 17336
Linux: RHEL6.10 Santiago
When I used sed
with -n
(which is used for silent mode), it works for the original file, but why it ended up creating a new file with no effect on the file and with the same name + suffixed a character n
in the file's extension, see below - File: /tmp/11.txtn
.
-n, --quiet, --silent
suppress automatic printing of pattern space
Here
[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]$
Upvotes: 2
Views: 1290
Reputation: 212484
When you invoke sed -in
, you are not passing the argument -n
. Instead, you are passing n
as the suffix of the backup file to -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.
Upvotes: 3
Reputation: 242038
-i
takes an optional parameter that denotes the extension of a backup file. Use -n -i
or specify an extension (-n -i~
is common).
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if SUFFIX supplied)
Upvotes: 4