{"id":307,"date":"2020-07-17T03:14:00","date_gmt":"2020-07-17T03:14:00","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=307"},"modified":"2020-12-17T03:16:43","modified_gmt":"2020-12-17T03:16:43","slug":"reading-content-of-a-file-using-bash","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/reading-content-of-a-file-using-bash\/","title":{"rendered":"Reading content of a file using bash"},"content":{"rendered":"\n<p>The following code read the contents of a text file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\nfilename='links.txt'\nwhile read -r line\ndo\n    echo $line\ndone &lt;\"$filename\"<\/code><\/pre>\n\n\n\n<p>To read first five lines only<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>head -5 dinks.txt | while read a; do\n    echo $a;\ndone<\/code><\/pre>\n\n\n\n<p>Read five lines and then delete those lines<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>head -5 links.txt | while read a; do\n    echo $a;\ndone\nsed -i \"1,5 d\" links.txt<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The following code read the contents of a text file To read first five lines only Read five lines and then delete those lines<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101,34],"tags":[94,35],"class_list":["post-307","post","type-post","status-publish","format-standard","hentry","category-bash","category-linux","tag-bash","tag-linux"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/307","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=307"}],"version-history":[{"count":1,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/307\/revisions"}],"predecessor-version":[{"id":308,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/307\/revisions\/308"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}