{"id":6938,"date":"2022-10-25T21:24:41","date_gmt":"2022-10-25T21:24:41","guid":{"rendered":"https:\/\/www.geekdecoder.com\/?p=6938"},"modified":"2022-10-25T21:24:41","modified_gmt":"2022-10-25T21:24:41","slug":"how-to-write-append-multiple-lines-to-a-file-on-linux","status":"publish","type":"post","link":"https:\/\/www.qbytes.cloud\/index.php\/2022\/10\/25\/how-to-write-append-multiple-lines-to-a-file-on-linux\/","title":{"rendered":"How to Write\/Append Multiple Lines to a File on Linux"},"content":{"rendered":"<p> This article describes how to add lines to a file in linux.<\/p>\n<p><!--more--><\/p>\n<p>You can write\/append content line by line using the multiple echo commands. <\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\necho &quot;line 1 content&quot; &gt;&gt;newfile.txt\n<\/pre>\n<p>You can append content with the multi-line command in the quoted text. <\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\necho &quot;line 1 content\nline 2 content\nline 3 content&quot; &gt;&gt; newfile.txt\n<\/pre>\n<p>Write a block of multiple lines text in a single command. <\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ncat &gt;&gt; newfile.txt &lt;&lt;EOL\nline 1 content\nline 2 content\nline 3 content\nEOL\n<\/pre>\n<p>Using a bash file.<\/p>\n<p>Use the bash file to add multiple lines.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nnano addlines.sh\n<\/pre>\n<p>Add the lines:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#!\/bin\/bash\ncat &gt;&gt; newfile.txt &lt;&lt;EOL\nline 1 content\nline 2 content\nline 3 content\nEOL\n<\/pre>\n<p>Save the file and then change the permissions to chmod +x addlines.sh<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nchmod +x addlines.sh\n<\/pre>\n<p>Execute the file<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n.\/addlines.sh\n<\/pre>\n<p>See the results:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ncat newfile.txt\nline 1 content\nline 2 content\nline 3 content\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This article describes how to add lines to a file in linux.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[139],"class_list":["post-6938","post","type-post","status-publish","format-standard","hentry","category-administration","tag-linux"],"_links":{"self":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/6938","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/comments?post=6938"}],"version-history":[{"count":0,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/6938\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/media?parent=6938"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/categories?post=6938"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/tags?post=6938"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}