cs360/notes/33.ed+ex and also awk
Why
You have to use an editor to make 'vi' and 'emacs' work
sometimes. And if they don't work.... what's left?
Sheer unadulterated power: Editting 40 files with a single command.
The rush of Extreme Editing:-)
To program a repetitive action on a file.
Sections
(why): 33.01 33.02
(exam): 33.03 33.04 33.05
(useful): 33.02 33.03 33.04 33.05 33.07
(PostIt Note): 33.03 33.04 33.11
(perhaps): 33.06 33.08 33.12
(skip): 33.09 33.10
(wrong):
Facts
I use ed, ex, and awk all the time -- mainly inside scripts.
Even mail and mailx were influened by ed and ex.
Definitions
- normal_ed_command::= ed file.
- batch_ed_command::= ed - file <<terminator eoln commands terminator
- command::= addresses action.
- action::=following
- a::action, append.
- c::action, change.
- d::action, delete.
- i::action, insert.
- m::action, move.
- p::action, print.
- q::action, quit.
- r::action, read.
- s::action, substitute.
- t::action, copy.
- w::action, write.
- Plus some multiple character commands
- addresses::= empty | address | address, address | whole_file_indicator | global_edit.
- global_edit::= g/ pattern /.
- address::= simple_address | relative_address | simple_address plus_or_minus number.
- relative_address::= + number | - number | + | - .
- simple_address::= before_top | last_line | current_line | marked_line | next_line_to_match | previous_line_to_match.
- before_top::= 0.
- last_line::= $.
- current_line::= period.
- marked_line::= ' letter.
- next_line_to_match::= / pattern /.
- previous_line_to_match::= ? pattern ?.
- whole_file_indicator::= %
- normal_string_delimeter::= /.
Edit Actions and Symbols
- append::= a lines.
- change::= c lines.
- delete::= d.
- edit::= e force_it_option other_file_symbol | e force_it_option file_name.
- other_file_symbol::= #.
- insert::= i lines.
- move::= m address.
- print::= p.
- quit::= q.
- read::= r source.
- source::= file_name | ! unix_command.
- substitute::= s / old_string / new_string / flags.
- flags::= any of g(global) + c(confirm) + p(print result).
- old_string::=pattern | empty.
- new_string::=any string of characters but escape special chars like & and /.
copy.
- write::= w force_it_option append_it_option destination_option.
- force_it_option::= empty | ! .
- append_it_option::= empty | >>.
- destination_option::= empty | file_name.
- Symbols::=following
- dollar::ed_symbol= $ , last_line.
- percent::ex_symbol=%, whole_file_indicator.
- plus::ex_symbol=+, relative_address.
- minus::ex_symbol= - , relative_address.
- single_quote::ex_symbol=' , marked_line.
- period::ed_symbol= . , current_line.
- g::ed_symbol, global_edit.
- slash::ed_symbol = / , search for next_line_to_match and normal_string_delimeter.
- question_mark::ed_symbol = ? , search for previous_line_to_match.
- exclamation_mark::ed_symbol = ! , force_it_option.
- pattern::= See http://www.csci.csusb.edu/dick/cs360/notes/26.patterns.html
- pattern::= See http://www.csci.csusb.edu/dick/cs360/notes/26.patterns.html
- file_name::==http://www.csci.csusb.edu/dick/cs360/notes/18.files.html#filename
- file_name::==http://www.csci.csusb.edu/dick/cs360/notes/18.files.html#filename
- number::=decimal number.
- letter::= a..z.
- empty::=
- TBA::=To Be Answered.
See also
An example of using ed to set up the notes for this
class.... I needed to move the "Questions" section to the
end of the notes and did it with an 'ed' script
//www/dick/cs360/notes/fix.ed
//www/dick/cs360/notes/fix.ed
As another example, I was asked how to put a line in front
of a file (its easy to add a line at the end with
echo line >>file
) but how to prepend a line into file. Answer the
[ prepend ]
script. You call it like this:
prepend file_name line to put in front of file
Awk
Awk is both useful and on the final exam, See
- awk::= See http://www.csci.csusb.edu/dick/cs360/notes/awk.html
- awk::= See http://www.csci.csusb.edu/dick/cs360/notes/awk.html
Questions
Answer the following questions about the 'ed' editor:
- What does a '$' mean in front of a command
?
- What does a '$' meaan in a search string
?
- What two symbols go around search strings and patterns in ed/ex/vi/sed/awk
?
- What does /abc/s/xyz/012/ do
?
- what does g/123/s///g do
?
- What does +5 do
?
- What does /QUESTION/,+5p do
?
- What does e! do
?
[ Questions in awk ]
[ Questions in awk ]
Submit Your Notes Here
To earn credit for completing this part of the course
you need to send me a short list of things you have learned.
A simple way to do this is to
follow this
[click here
if you can fill this hole]
link and fill in the form.