Talk Minutes - Ed - The Text Editor - June 16, 2020

Following are the important points discussed today about ‘ed’

  1. history about ed
  2. how to invoke ed
  3. why ‘ed’ is a line editor
  4. details about command mode
  5. details about input mode
  6. line numbers in ed
  7. how to add content to ‘ed’ current buffer
  8. how to display whole buffer
  9. print specific line or lines using line addresses
  10. deleting and changing lines
  11. saving current buffer to filesystem
  12. opening files in ed
  13. using regular expression instead of line address in ed
  14. forward searching
  15. reverse searching
  16. global searching
  17. intro to Basic Regular Expressions (BRE)

Session Replay

ed-talk

IRC Logs

2020-06-16 16:00:17 mohan43u-we welcome to ILUGC #irc channel
2020-06-16 16:01:14 mohan43u-we wait for another 5 more mins for people to join
2020-06-16 16:01:46 mohan43u-we I hope everyone can see the presenter terminal
2020-06-16 16:03:09 --> mohan43u-kiwi (~mohan43u-@2a01:4f9:c010:82aa::1) has joined #ilugc
2020-06-16 16:03:43 stof9-9 link please
2020-06-16 16:04:00 mohan43u-we stof9-9: https://training.ilugc.in
2020-06-16 16:04:09 stof9-9 thanks
2020-06-16 16:04:32 --> famubu__1 (~famubu@117.207.224.45) has joined #ilugc
2020-06-16 16:04:57 mohan43u-we lets start the talk
2020-06-16 16:05:23 mohan43u-we this talk is about 'ed' the text editor
2020-06-16 16:05:51 mohan43u-we it is created by Ken thomson for original unix
2020-06-16 16:06:06 --> stof999-kiwi (~stof999-k@2a01:4f9:c010:82aa::1) has joined #ilugc
2020-06-16 16:06:27 mohan43u-we the idea about ed came when he was in berkeley
2020-06-16 16:06:58 mohan43u-we he first implemented ed for CTSS then ported it to multics
2020-06-16 16:07:36 mohan43u-we again, when he developed unix, 'ed' was the editor of choice
2020-06-16 16:07:49 mohan43u-we along with shell 'sh'
2020-06-16 16:08:38 mohan43u-we Ken implemented regular expressions in ed way back before unix, in CTSS
2020-06-16 16:08:56 mohan43u-we ed is a line editor
2020-06-16 16:09:36 mohan43u-we most of you might be familier with 'vi' which is also a line editor
2020-06-16 16:09:44 mohan43u-we ed operates in two modes
2020-06-16 16:09:50 mohan43u-we one is command mode
2020-06-16 16:09:58 mohan43u-we and the next is input mode
2020-06-16 16:10:13 mohan43u-we when 'ed' starts, it will be started in command mode
2020-06-16 16:10:32 mohan43u-we you can switch between command/input modes
2020-06-16 16:11:03 mohan43u-we before I start the demo, I would like everyone to use the practice terminal to see how ed works
2020-06-16 16:11:14 mohan43u-we 'ed' command is available in practice session
2020-06-16 16:11:26 mohan43u-we so, lets start now
2020-06-16 16:11:56 mohan43u-we a simple ed command with show nothing, not even a prompt
2020-06-16 16:12:08 mohan43u-we just assume that you are in command mode
2020-06-16 16:12:22 mohan43u-we any characters you type are commands to ed
2020-06-16 16:12:38 mohan43u-we I just typed ww and press enter
2020-06-16 16:12:55 mohan43u-we ed said what? what do you mean by 'ww'? I dont understand
2020-06-16 16:13:26 mohan43u-we ofcourse it didn't say those. but we just assume whenever ed shows '?', it means 'ed' is confused
2020-06-16 16:14:02 mohan43u-we all those inputs 'ed' dont understand
2020-06-16 16:14:57 mohan43u-we the only brief help message 'ed' can show is oneliners when typing 'h' after 'ed' shows '?'
2020-06-16 16:15:34 mohan43u-we thus, when 'ed' shows ?, we have to type h to get somewhat brief help
2020-06-16 16:15:46 mohan43u-we now, we are in command mode
2020-06-16 16:15:57 mohan43u-we and also, there is something called current line
2020-06-16 16:16:42 mohan43u-we see, the '.' command usually will tell you which line you are, but our buffer is not having any lines
2020-06-16 16:16:53 mohan43u-we so ed throwed one error
2020-06-16 16:17:17 mohan43u-we I asked a brief error, and it showed that there is no address as current line
2020-06-16 16:17:27 mohan43u-we now, add some content to our current buffer
2020-06-16 16:17:30 --> shrini-kiwi (~shrini-ki@2a01:4f9:c010:82aa::1) has joined #ilugc
2020-06-16 16:18:01 mohan43u-we the input 'i', 'a', 'A' can help switch 'ed' from command mode to input mode
2020-06-16 16:18:56 --> Mir (~Mir@2a01:4f9:c010:82aa::1) has joined #ilugc
2020-06-16 16:18:58 mohan43u-we so I added three lines, now I want to switch back to command mode,
2020-06-16 16:19:21 -- Mir is now known as Guest67250
2020-06-16 16:21:37 mohan43u-we any line start with '.' character in input mode will switch 'ed' to command mode
2020-06-16 16:21:37 mohan43u-we now, ed is in command mode
2020-06-16 16:21:37 mohan43u-we see, when I typed a line forgetting that I'm in command mode, 'ed' throwed error
2020-06-16 16:21:37 mohan43u-we just to get a brief help
2020-06-16 16:21:37 mohan43u-we now, we can see how to print the buffer
2020-06-16 16:21:38 mohan43u-we in ed, every line have a address associated with it
2020-06-16 16:21:38 mohan43u-we line address start from 1
2020-06-16 16:22:01 Guest67250 hi
2020-06-16 16:22:14 mohan43u-we I just typed '1' and pressed enter, 'ed' showed that line
2020-06-16 16:22:37 mohan43u-we '1' internally befomes '1p'
2020-06-16 16:22:50 mohan43u-we here 'p' means 'print'
2020-06-16 16:23:08 --> paulpandi (~paulpandi@2a01:4f9:c010:82aa::1) has joined #ilugc
2020-06-16 16:23:54 mohan43u-we most of the ed command have this general syntex <start>,<end><command>
2020-06-16 16:23:59 <-- Guest67250 (~Mir@2a01:4f9:c010:82aa::1) has quit (Quit: Client closed)
2020-06-16 16:24:30 mohan43u-we I just typed 1,$p
2020-06-16 16:24:32 --> Murugan (~Murugan@2a01:4f9:c010:82aa::1) has joined #ilugc
2020-06-16 16:24:40 mohan43u-we here, $ represents the end line
2020-06-16 16:24:46 mohan43u-we or the last line
2020-06-16 16:25:13 mohan43u-we the same, line 1,$p, but instead of using p, I used n
2020-06-16 16:25:15 <-- paulpandi (~paulpandi@2a01:4f9:c010:82aa::1) has quit (Client Quit)
2020-06-16 16:25:24 mohan43u-we n means print along with line addresses
2020-06-16 16:26:00 mohan43u-we now, remember I said about '.'?
2020-06-16 16:26:03 mohan43u-we now try that
2020-06-16 16:26:26 mohan43u-we see, the '.' represents line which was last modified
2020-06-16 16:26:55 mohan43u-we the third line was the line we added last, so '.' now points to the third line
2020-06-16 16:27:49 mohan43u-we if you dont give any address but simply try to use the command, then it means, you are operating on the current line which is the third line
2020-06-16 16:28:19 --> Mir (~Mir@2a01:4f9:c010:82aa::1) has joined #ilugc
2020-06-16 16:28:24 <-- Murugan (~Murugan@2a01:4f9:c010:82aa::1) has quit (Client Quit)
2020-06-16 16:28:36 mohan43u-we the current line now changed to first line after I typed 1, because it is the line last printed (a command operated on it)
2020-06-16 16:28:42 -- Mir is now known as Guest91114
2020-06-16 16:29:40 mohan43u-we as you see, by typing ',n' or ',p' we are implicitly telling '1,$n' or '1,$p'
2020-06-16 16:30:11 mohan43u-we now, we have a buffer with three lines in 'ed'
2020-06-16 16:30:30 mohan43u-we this buffer is still in memory, not written to file in filesystem
2020-06-16 16:31:01 mohan43u-we the command to write the buffer back to file system is 'w'
2020-06-16 16:31:28 mohan43u-we we need to give 'w' a filename, otherwise 'ed' with throw its confused signal
2020-06-16 16:31:40 mohan43u-we see, it says no current filename
2020-06-16 16:32:16 mohan43u-we after I gave filename, it showed how many characters it got written into the file
2020-06-16 16:33:03 mohan43u-we I did a mistake in the fourth line
2020-06-16 16:33:20 mohan43u-we I want to delete it, so here is how we delete
2020-06-16 16:33:32 --> humachine (~ranjith@unaffiliated/humachine) has joined #ilugc
2020-06-16 16:33:34 mohan43u-we the fourth line gone
2020-06-16 16:34:38 mohan43u-we see, I mistakenly typed ',n' when I was in input mode, quickly realized that I was in input mode
2020-06-16 16:34:56 mohan43u-we so I switched back to command mode using '.' in a single line and then typed only 'd'
2020-06-16 16:35:15 mohan43u-we which means, delete the last operated line (or simply the current line)
2020-06-16 16:35:31 mohan43u-we now we have 4 lines
2020-06-16 16:36:01 stof999-kiwi :)
2020-06-16 16:36:19 mohan43u-we but if you look at the file which we wrote, we only have three lines
2020-06-16 16:36:29 mohan43u-we it means, the fourth line was not written
2020-06-16 16:36:39 mohan43u-we written into the filesystem
2020-06-16 16:36:55 mohan43u-we we have to write everytime we modify the buffer
2020-06-16 16:37:25 stof999-kiwi ?
2020-06-16 16:37:30 mohan43u-we emacs can save all your updates into the buffer in a temporary file which starts with '#<filename>#',
2020-06-16 16:37:42 mohan43u-we same way, vi can store your current buffer as .swp file
2020-06-16 16:38:04 mohan43u-we but 'ed' is a dumb one, it will not do unless you ask it to do
2020-06-16 16:38:10 --> shrini1 (uid38773@gateway/web/irccloud.com/x-tclexuxmbnumuezo) has joined #ilugc
2020-06-16 16:38:12 mohan43u-we stof999-kiwi: please ask
2020-06-16 16:38:25 stof999-kiwi no warning? nothing?
2020-06-16 16:38:32 mohan43u-we stof999-kiwi: nothing
2020-06-16 16:38:53 mohan43u-we stof999-kiwi: thats why it is called real programmers editor :)
2020-06-16 16:39:11 mohan43u-we continuing my talk.
2020-06-16 16:39:31 mohan43u-we here is how we can update the content of the current buffer into the filesystem
2020-06-16 16:39:51 mohan43u-we see, last time when we did 'w', 'ed' throwed confused signal, butnow
2020-06-16 16:39:56 mohan43u-we but now, it didn't
2020-06-16 16:40:27 mohan43u-we because we already told 'ed' that associate 'ed-turorial.txt' file with the current buffer
2020-06-16 16:40:53 mohan43u-we or in other ways, the filename we gave to 'ed' was used as current file for the current buffer
2020-06-16 16:41:29 mohan43u-we now you can see that both buffer contents and file contents matches
2020-06-16 16:41:53 mohan43u-we to quit 'ed', just type q
2020-06-16 16:42:46 mohan43u-we see, I just typed one more line (added content to buffer), but that line was not saved into filesystem
2020-06-16 16:43:07 mohan43u-we 'ed' just throwed its famous confused signal
2020-06-16 16:43:11 mohan43u-we let see what it says
2020-06-16 16:43:33 mohan43u-we it says buffer was modified but it is not updated into filesystem
2020-06-16 16:43:45 --> sam73 (~sam@2a01:4f9:c010:82aa::1) has joined #ilugc
2020-06-16 16:43:54 mohan43u-we now I wrote the buffer content back to filesystem
2020-06-16 16:44:13 mohan43u-we now 'q' didn't throw any error and simply edited
2020-06-16 16:44:56 mohan43u-we so this file 'ed-tutorial.txt' is the final product of our 'ed' session
2020-06-16 16:45:14 mohan43u-we before moving to the next part, if anyone have query please raise
2020-06-16 16:46:11 mohan43u-we continuing my talk
2020-06-16 16:47:44 mohan43u-we I just started 'ed' and loaded the current buffer with the content from 'ed-tutorial.txt' file
2020-06-16 16:47:52 mohan43u-we with the 'e' command
2020-06-16 16:48:27 mohan43u-we 'e' command will read the contents from the file and load the current buffer with the contents
2020-06-16 16:49:32 mohan43u-we without quiting ed, I again typed 'e' command to load another file
2020-06-16 16:50:09 mohan43u-we so 'e' command flushed the current buffer, and loaded the new file
2020-06-16 16:50:46 mohan43u-we I forgot the filename which we used, so I run a shell command from inside 'ed' using '!'
2020-06-16 16:51:32 mohan43u-we now I loaded the correct file
2020-06-16 16:53:21 mohan43u-we the 'c' command will change the line you specify
2020-06-16 16:54:01 mohan43u-we more specifically, it will switch 'ed' into input mode after flush out that specific line
2020-06-16 16:54:08 mohan43u-we lets change the first line
2020-06-16 16:54:20 --> IRG (~IRG@2a01:4f9:c010:82aa::1) has joined #ilugc
2020-06-16 16:54:42 <-- IRG (~IRG@2a01:4f9:c010:82aa::1) has quit (Client Quit)
2020-06-16 16:55:26 mohan43u-we instead of giving line address, you can provide basic regular expressions to ed commands
2020-06-16 16:55:29 --> SK98 (~SK@2a01:4f9:c010:82aa::1) has joined #ilugc
2020-06-16 16:55:55 mohan43u-we '/third/'n means, print any line which contains word 'third'
2020-06-16 16:57:36 mohan43u-we when we omit 'g' at the beginning, /<re>/n will not into the lines from the current line to the end line and look for the <re>
2020-06-16 16:57:50 mohan43u-we currently we are in the second line
2020-06-16 16:57:59 mohan43u-we now search for buffer
2020-06-16 16:58:22 mohan43u-we it only printed the next line which contains word 'buffer'
2020-06-16 16:58:39 mohan43u-we now, we are currently in third line
2020-06-16 16:59:14 mohan43u-we ?<re>? syntex will search for <re> from current line back to first line
2020-06-16 16:59:43 mohan43u-we just showing example how '?' works
2020-06-16 17:00:54 mohan43u-we so the ?<re>? wrap around and search backwards
2020-06-16 17:01:24 mohan43u-we /<re>/ wraps and search forward
2020-06-16 17:02:03 mohan43u-we the global 'g' command operates on the whole buffer matching any line which contains 'buffer'
2020-06-16 17:02:30 mohan43u-we g/<re>/p
2020-06-16 17:02:50 mohan43u-we is basically the famous 'grep' command
2020-06-16 17:04:13 mohan43u-we 'ed' operates with BRE
2020-06-16 17:04:19 mohan43u-we basic regular expression
2020-06-16 17:04:40 shrini1 Wow
2020-06-16 17:05:11 mohan43u-we I thought of giving brief intro to BRE, but the talk time is not enough to explain about BRE
2020-06-16 17:06:03 <-- Guest91114 (~Mir@2a01:4f9:c010:82aa::1) has quit (Quit: Client closed)
2020-06-16 17:06:18 mohan43u-we https://man7.org/linux/man-pages/man7/regex.7.html
2020-06-16 17:06:29 mohan43u-we this is a simple intro to Regular Expressions
2020-06-16 17:06:56 mohan43u-we this is proper man page of 'ed' https://man7.org/linux/man-pages/man1/ed.1p.html
2020-06-16 17:07:33 mohan43u-we 'ed' is part of posix, so any operating system which claims to be posix compatible will have 'ed'
2020-06-16 17:08:09 mohan43u-we the link to the manual page which I gave will provide details about how 'ed' should operate in a posix environment
2020-06-16 17:08:39 mohan43u-we different unix flavours implemented 'ed' in various ways
2020-06-16 17:09:16 mohan43u-we most of the Linux distros uses GNU 'ed'
2020-06-16 17:09:30 mohan43u-we https://www.gnu.org/software/ed/
2020-06-16 17:09:55 stof999-kiwi ?
2020-06-16 17:10:33 mohan43u-we concluding my talk with this famous joke about editors https://xkcd.com/378/
2020-06-16 17:11:05 mohan43u-we thats it. thanks for attendint the talk. please ask questions/discuss freely
2020-06-16 17:11:10 mohan43u-we stof999-kiwi: please ask
2020-06-16 17:11:18 stof999-kiwi clap, clap
2020-06-16 17:11:20 mohan43u-we ^s/attendint/attending/g
2020-06-16 17:11:53 mohan43u-we stof999-kiwi: thanks
2020-06-16 17:12:33 stof999-kiwi what are the main diff between posix- and gnu-ed?
2020-06-16 17:13:17 mohan43u-we stof999-kiwi: gnu contains few more then the posix
2020-06-16 17:14:02 mohan43u-we stof999-kiwi: I'm not aware of the differences right now. I need to check the differences
2020-06-16 17:14:37 stof999-kiwi it's ok. thanks
2020-06-16 17:16:20 mohan43u-we talk concluded. #ilugc channel floor is open to anyone to talk. feel free to hang in hear and have fun
2020-06-16 17:16:33 mohan43u-we s/^hear/here/g

Terminal Capture Logs

ed-talk-script-output-files.tar.gz

To playback these logs, follow these steps

$ tar xvzf ed-talk-script-output-files.tar.gz
$ scriptreplay -m1 --timing=20200616155221-24417.timing 20200616155221-24417.typescript