Inserting text at the beginning or end of a line

Use the s (substitute) subcommand and these two special substitution characters to insert text at the beginning or end of a line:
^ (circumflex)
Inserts text at the beginning of a line
$ (dollar sign)
Inserts text at the end of a line
  • To insert text at the beginning of the current working line, enter:
    s/^/newtext
  • To insert text at the beginning of a specified line, enter:
    ns/^/newtext
    where n is the number of the line. This line becomes the current working line.
  • To insert text at the end of the current working line, enter:
    s/$/newtext
  • To insert text at the end of a specified line, enter:
    ns/$/newtext
    where n is the number of the line. This line becomes the current working line.