{"id":7385,"date":"2024-09-05T03:00:00","date_gmt":"2024-09-05T07:00:00","guid":{"rendered":"https:\/\/www.both.org\/?p=7385"},"modified":"2024-09-04T10:57:59","modified_gmt":"2024-09-04T14:57:59","slug":"editing-files-with-freedos-edlin","status":"publish","type":"post","link":"https:\/\/www.both.org\/?p=7385","title":{"rendered":"Editing files with FreeDOS Edlin"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"7385\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\r\n<\/div><\/div>\n<p>Back in the early days of PC computing, Tim Paterson created the Edlin editor for an early \u201cDOS\u201d operating system called 86-DOS (also called \u201cQDOS\u201d). Paterson\u2019s Edlin was a <em>line editor<\/em>, based on the CP\/M editor <strong>ed<\/strong>, which itself was loosely based on the Unix editor <strong>ed<\/strong>.<\/p>\n\n\n\n<p>Paterson has since said that he never intended Edlin to have a long life, it was just something he created so he could write programs. He always meant for Edlin to be replaced by a better text editor. But Edlin did the job, and when 86-DOS became PC-DOS (and later, MS-DOS) Edlin became the default editor. And it remained so until MS-DOS 5 in 1991, which replaced the line editor with Edit, a full-screen editor.<\/p>\n\n\n\n<p>The Edlin editor lives on in FreeDOS Edlin, originally written by Gregory Pietsch. FreeDOS Edlin is very similar to the classic Edlin, but I find it\u2019s easier to use. And unlike classic Edlin, FreeDOS Edlin is highly portable, which means you can download the source code from <a href=\"https:\/\/sourceforge.net\/projects\/freedos-edlin\/\">FreeDOS Edlin on SourceForge<\/a> and compile it on your favorite operating system.<\/p>\n\n\n\n<p>Here\u2019s a brief primer to using FreeDOS Edlin:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"start-by-editing-a-file\">Start by editing a file<\/h2>\n\n\n\n<p>The most common way to start Edlin is by giving it the name of a file to edit. I\u2019ll start by writing a simple \u201cHello world\u201d program in C. If this is a new file, Edlin will let you know:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ edlin hello.c\nhello.c: New file.\n*<\/code><\/pre>\n\n\n\n<p>The <code>*<\/code> is Edlin\u2019s friendly prompt where you can enter commands. Like other line editors, with Edlin, you are either in <em>command<\/em> mode at the Edlin prompt, or you are in <em>edit mode<\/em> to enter text. To see a list of commands you can use in Edlin, type <code>?<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>*?\nedlin 2.24, copyright (c) 2003 Gregory Pietsch\nThis program comes with ABSOLUTELY NO WARRANTY.\nIt is free software, and you are welcome to redistribute it\nunder the terms of the GNU General Public License -- either\nversion 2 of the license, or, at your option, any later\nversion.\n\n\nedlin has the following subcommands:\n\n#                 edit a single line    &#91;#],&#91;#],#m        move\na                 append                &#91;#]&#91;,#]p          page\n&#91;#],&#91;#],#,&#91;#]c    copy                  q                 quit\n&#91;#]&#91;,#]d          delete                &#91;#]&#91;,#]&#91;?]r$,$    replace\ne&lt;&gt;               end (write &amp; quit)    &#91;#]&#91;,#]&#91;?]s$      search\n&#91;#]i              insert                &#91;#]t&lt;&gt;            transfer\n&#91;#]&#91;,#]l          list                  &#91;#]w&lt;&gt;            write\n\nwhere $ above is a string, &lt;&gt; is a filename,\n# is a number (which may be .=current line, $=last line,\nor either number + or - another number).\n\n*<\/code><\/pre>\n\n\n\n<p>These commands will become more familiar as you get some practice in editing files in Edlin.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"appending-new-lines\">Appending new lines<\/h2>\n\n\n\n<p>If you have an empty file, you can use either the <code>a<\/code> (append) or <code>i<\/code> (insert) command to start entering new lines. Let\u2019s use the <code>a<\/code> command to append some new text at the end of the file; since this is an empty file, this adds new lines:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>*a\n : int main()\n : {\n :   puts(\"Hello world\");\n : .\n*<\/code><\/pre>\n\n\n\n<p>When entering text, the Edlin prompt changes to <code>:<\/code> so you know that you are in edit mode. Type <code>.<\/code> on a line by itself to stop entering text and go back to command mode.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"viewing-the-file\">Viewing the file<\/h2>\n\n\n\n<p>To see what you\u2019ve entered into the file, use the <code>l<\/code> (list) command. This will automatically display ten lines above the current line and ten lines after it, but for this short file it displays everything:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>*l\n1: int main()\n2: {\n3:*  puts(\"Hello world\");\n*<\/code><\/pre>\n\n\n\n<p>Each line is numbered so you can refer to a specific line as you edit the file. The <code>*<\/code> on line 3 indicates that this is the <em>current<\/em> line.<\/p>\n\n\n\n<p>However, the <code>a<\/code> (append) command always appends to the end of the file, which can be a little misleading if our current line is already the last line in the file. Just remember that <code>a<\/code> will append to the end. Let\u2019s use the <code>a<\/code> command to add the missing curly brace to end the program:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>*a\n : }\n : .\n*l\n1: int main()\n2: {\n3:   puts(\"Hello world\");\n4:*}\n*<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"inserting-new-lines\">Inserting new lines<\/h2>\n\n\n\n<p>It\u2019s important to <em>know where you are<\/em> in a file when working in Edlin, so that <code>*<\/code> after the line number is an important indicator. Let\u2019s say we wanted to insert a new line <em>before<\/em> the current line. We can use the <code>i<\/code> command, which will always insert <em>before<\/em> a line. Let\u2019s add the missing <code>return<\/code> statement to our C program:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>*i\n :   return 0;\n : .\n*l\n1: int main()\n2: {\n3:   puts(\"Hello world\");\n4:   return 0;\n5:*}\n*<\/code><\/pre>\n\n\n\n<p>After inserting the new line, the <em>current<\/em> line is still the last line in the file, which is now line 5.<\/p>\n\n\n\n<p>But you don\u2019t have to limit yourself to only working on the current line. You can also use a line number with the <code>i<\/code> command to insert new text <em>before<\/em> another line. Let\u2019s add an <code>#include<\/code> statement to the start of our C program, before line 1:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>*1i\n : #include &lt;stdio.h&gt;\n : \n : .\n*l\n1: #include &lt;stdio.h&gt;\n2: \n3:*int main()\n4: {\n5:   puts(\"Hello world\");\n6:   return 0;\n7: }\n*<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"editing-lines\">Editing lines<\/h2>\n\n\n\n<p>If you want to edit a specific line in a file, type the line number that you want to change. Edlin will print the line from the file, then automatically replace that line with whatever new text you enter. Let\u2019s change line 5 to print a slightly different message:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>*5\n5:*  puts(\"Hello world\");\n5:   puts(\"Hi there!\");\n*l\n1: #include &lt;stdio.h&gt;\n2: \n3: int main()\n4: {\n5:*  puts(\"Hi there!\");\n6:   return 0;\n7: }\n*<\/code><\/pre>\n\n\n\n<p>After editing the line, Edlin returns you to command mode and sets the <em>current<\/em> line to the line you just entered. This makes it easy to insert new lines before it with the <code>i<\/code> command, if you needed to keep modifying the file at this line.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"moving-lines\">Moving lines<\/h2>\n\n\n\n<p>A handy feature of any text editor is to move text around a file. Because Edlin is a line editor, Edlin can only move <em>entire lines<\/em> at a time. But for most files, this is usually what you want to do anyway.<\/p>\n\n\n\n<p>Let\u2019s demonstrate it by entering a comment about the program, but appending it at the end of the file with the <code>a<\/code> command. Notice that the <em>current<\/em> line is line 5, but the <code>a<\/code> command actually adds text at the end of the file. We can move this new line later:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>*l\n1: #include &lt;stdio.h&gt;\n2: \n3: int main()\n4: {\n5:*  puts(\"Hi there!\");\n6:   return 0;\n7: }\n*a\n : \/* a sample program *\/\n : .\n*l\n1: #include &lt;stdio.h&gt;\n2: \n3: int main()\n4: {\n5:   puts(\"Hi there!\");\n6:   return 0;\n7: }\n8:*\/* a sample program *\/\n*<\/code><\/pre>\n\n\n\n<p>A better place for this comment is on the first line of the file. We can move one or more lines with the <code>m<\/code> (move) command, which has the general syntax of <code>[#],[#],#m<\/code>. That is, the first line to move, the last line to move, then the new line where the text should go, all separated with commas. In our case, we want to move line 8 to before line 1:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>*8,8,1m\n*l\n1: \/* a sample program *\/\n2: #include &lt;stdio.h&gt;\n3: \n4: int main()\n5: {\n6:   puts(\"Hi there!\");\n7:   return 0;\n8:*}\n*<\/code><\/pre>\n\n\n\n<p>And we can make it look nice by inserting (<code>i<\/code>) a blank line before line 2:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>*2i\n : \n : .\n*l\n1: \/* a sample program *\/\n2: \n3:*#include &lt;stdio.h&gt;\n4: \n5: int main()\n6: {\n7:   puts(\"Hi there!\");\n8:   return 0;\n9: }\n*<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"saving-and-exiting\">Saving and exiting<\/h2>\n\n\n\n<p>When you\u2019re done making changes, don\u2019t forget to save your new file using the <code>w<\/code> (write) command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>*w\nhello.c: 9 lines written\n*<\/code><\/pre>\n\n\n\n<p>Once the file is safely written to disk, you can exit Edlin using the <code>q<\/code> (quit) command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>*q\nReally quit (Y\/n)? y<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"theres-more-to-explore\">There\u2019s more to explore<\/h2>\n\n\n\n<p>Edlin is a classic editor from the early DOS days, but it\u2019s still a fun and useful editor. I use Edlin when I want to write something quickly, like a test program or a brief note. Edlin is also very useful if you want to capture some commands into a FreeDOS batch file; you can write the new batch file while any commands you ran are still visible on the screen.<\/p>\n\n\n\n<p>You can get pretty far with inserting, appending, editing, and moving lines in a file. But there\u2019s more to explore! Use the <code>?<\/code> (help) command to see all the commands supported in FreeDOS Edlin.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Edlin is a classic editor from the early DOS days, but it\u2019s still a fun and useful editor.<\/p>\n","protected":false},"author":33,"featured_media":3522,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[340,218],"tags":[267,221],"class_list":["post-7385","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-freedos","category-text-editors","tag-freedos","tag-text-editors"],"modified_by":"Jim Hall","_links":{"self":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/7385","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/users\/33"}],"replies":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7385"}],"version-history":[{"count":1,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/7385\/revisions"}],"predecessor-version":[{"id":7387,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/7385\/revisions\/7387"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/3522"}],"wp:attachment":[{"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7385"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7385"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7385"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}