Read a specific line from a file: Difference between revisions
simplify sed script
MaiconSoft (talk | contribs) (Added Delphi example) |
(simplify sed script) |
||
Line 1,694:
=={{header|sed}}==
To print the seventh line:
<lang sed>sed -n 7p</lang>
To print an error message, if no such line:▼
That is we remember (h) the line, if any, in hold space. At the last line ($) we exchange (x) pattern space and hold space. If the hold space was empty,
▲To print error message if no such line
▲sed -n '7{p;h;}; ${x;/^$/s/^/Error: no such line/p}'
▲That is we remember (h) the line, if any, in hold space. At last line ($) we exchange (x) pattern space and hold space. If hold space was empty -- print error message.
=={{header|Seed7}}==
|