{"id":156,"date":"2020-01-16T11:56:54","date_gmt":"2020-01-16T10:56:54","guid":{"rendered":"http:\/\/xv6.de\/?page_id=156"},"modified":"2022-08-15T09:42:59","modified_gmt":"2022-08-15T08:42:59","slug":"show-a-given-line-number-from-file","status":"publish","type":"page","link":"https:\/\/xv6.de\/?page_id=156","title":{"rendered":"Show a given line number from file"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>sed 'NUMq;d' file<\/code><\/pre>\n\n\n\n<p>Where <em>NUM<\/em> is the number of the line you want to print; so, for example <em>sed &#8217;10q;d&#8217; file<\/em> to print the 10th line of <em>file<\/em>.<\/p>\n\n\n\n<p>Explanation: <\/p>\n\n\n\n<p><em>NUMq<\/em> will quit immediately when the line number is\u00a0<code><em>NUM<\/em><\/code>.<\/p>\n\n\n\n<p><em>d<\/em> will delete the line instead of printing it; this is inhibited on the last line because the <em>q<\/em> causes the rest of the script to be skipped when quitting.<\/p>\n\n\n\n<p>If you have <em>NUM<\/em> in a variable, you will want to use double quotes instead of single:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sed \"${NUM}q;d\" file<\/code><\/pre>\n\n\n\n<p>Source:  <a href=\"https:\/\/stackoverflow.com\/questions\/6022384\/bash-tool-to-get-nth-line-from-a-file\">https:\/\/stackoverflow.com\/questions\/6022384\/bash-tool-to-get-nth-line-from-a-file<\/a> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Where NUM is the number of the line you want to print; so, for example sed &#8217;10q;d&#8217; file to print the 10th line of file. Explanation: NUMq will quit immediately when the line number is\u00a0NUM. d will delete the line instead of printing it; this is inhibited on the last line because the q causes &hellip; <a href=\"https:\/\/xv6.de\/?page_id=156\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Show a given line number from file<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-156","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/xv6.de\/index.php?rest_route=\/wp\/v2\/pages\/156","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xv6.de\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/xv6.de\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/xv6.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xv6.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=156"}],"version-history":[{"count":8,"href":"https:\/\/xv6.de\/index.php?rest_route=\/wp\/v2\/pages\/156\/revisions"}],"predecessor-version":[{"id":240,"href":"https:\/\/xv6.de\/index.php?rest_route=\/wp\/v2\/pages\/156\/revisions\/240"}],"wp:attachment":[{"href":"https:\/\/xv6.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}