Difference between revisions of "Append"

From wikieduonline
Jump to navigation Jump to search
 
(19 intermediate revisions by 3 users not shown)
Line 1: Line 1:
  
 +
Append at the end of a [[file]]:
 +
:<code>[[echo]] "your_line_to_append" >> your_file.txt</code>
  
[[echo]] "your_line_to_append" >> your_file.txt
+
<code>[[history -a]]</code>
 
 
[[history -a]]
 
 
 
  
 
  [[tee --append]] ~/.ssh/config << END
 
  [[tee --append]] ~/.ssh/config << END
Line 11: Line 10:
 
  [[END]]
 
  [[END]]
  
 +
 +
Using <code>[[Sed (editor)|sed]]</code>
 +
* [[Append]] a text (TEST_TO_APPEND_AT_BEGINNIG) at the [[beginning]] of a line:
 +
:: <code>[[sed -i]] s/^/TEST_TO_APPEND_AT_BEGINNIG/ file.txt</code>
 +
 +
:: [[Append a space]] at the beginning of lines:
 +
::: <code>[[sed s/^/" "/]]</code>
 +
 +
* Append a text (TEST_TO_APPEND_AT_END) at the [[end of a line]] (<code>$</code>):
 +
:: <code>sed -i s/$/TEST_TO_APPEND_AT_END/ file.txt</code>
  
 
== Related ==
 
== Related ==
 
* <code>[[lineinfile]]</code>
 
* <code>[[lineinfile]]</code>
 +
* [[Shell redirection]]: <code>></code> and <code>>></code>
 +
* [[Prepend]]
 +
* [[list]]
 +
* [[Add line]]
  
 
== See also ==
 
== See also ==
 
* {{echo}}
 
* {{echo}}
 
* {{tee}}
 
* {{tee}}
 +
* {{Append}}
  
 
[[Category:Computing]]
 
[[Category:Computing]]

Latest revision as of 09:47, 19 April 2023

Append at the end of a file:

echo "your_line_to_append" >> your_file.txt

history -a

tee --append ~/.ssh/config << END
Host localhost
  ForwardAgent yes
END


Using sed

sed -i s/^/TEST_TO_APPEND_AT_BEGINNIG/ file.txt
Append a space at the beginning of lines:
sed s/^/" "/
sed -i s/$/TEST_TO_APPEND_AT_END/ file.txt

Related[edit]

See also[edit]

Advertising: