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

(Created page with "<pre>sed -i 'Ns/.*/replace-line-with-this-string/' file.txt</pre> in ''N'' you enter the line number. Please add your string in "''replace-line-with-this-string''". Catego...")
 
Line 2: Line 2:
  
 
in ''N'' you enter the line number. Please add your string in "''replace-line-with-this-string''".
 
in ''N'' you enter the line number. Please add your string in "''replace-line-with-this-string''".
 +
<br>
 +
 +
'''If you use a variable use this command:'''
 +
<pre>sed -i "Ns/.*/$variable/" file.txt
 +
</pre>
  
 
[[Category: Sed]]
 
[[Category: Sed]]
 
[[Category: Shell
 
[[Category: Shell

Revision as of 14:33, 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
[[Category: Shell