Difference between revisions of "Sed Shell - Replace an entire line number with a string"

 
Line 5: Line 5:
  
 
'''If you use a variable use this command:'''
 
'''If you use a variable use this command:'''
<pre>sed -i "Ns/.*/$variable/" file.txt
+
<pre>sed -i "Ns%.*%$variable%" file.txt
 
</pre>
 
</pre>
 
+
Here % is the delimiter instead of /
 
[[Category: Sed]]
 
[[Category: Sed]]
[[Category: Shell
+
[[Category: Shell]]

Latest revision as of 15:16, 20 September 2019

sed -i 'Ns/.*/replace-line-with-this-string/' file.txt

in N you enter the line number. Please add your string in "replace-line-with-this-string".

If you use a variable use this command:

sed -i "Ns%.*%$variable%" file.txt

Here % is the delimiter instead of /