Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Using sed, how can I append "START" above the first line and "END" below the last line?

Input file:

Steve Blenheim:238-923-7366:95 Latham Lane, Easton, PA 83755:11/12/56:20300

Betty Boop:245-836-8357:635 Cutesy Lane, Hollywood, CA 91464:6/23/23:14500

Igor Chevsky:385-375-8395:3567 Populus Place, Caldwell, NJ 23875:6/18/68:23400

Norma Corder:397-857-2735:74 Pine Street, Dearborn, MI 23874:3/28/45:245700

Jennifer Cowan:548-834-2348:583 Laurel Ave., Kingsville, TX 83745:10/1/35:58900

Jon DeLoach:408-253-3122:123 Park St., San Jose, CA 04086:7/25/53:85100
share|improve this question
up vote 6 down vote accepted

Use "addresses": 1 stand for the first line, ^ means the beginning of the line. $ stands for the last line in an address, and also means end-of-line in a regular expression.

sed -e '1s/^/START\n/' -e '$s/$/\nEND/'
share|improve this answer
Great! thank you Choroba ... – Steve Oct 8 '12 at 20:07
@Steve, if choroba's answer answers your question please mark it as accepted. – terdon Oct 8 '12 at 22:02

You can also do it without matching using i and a commands.

sed -e '1i START' -e '$a END'

but it comes to the same thing.

share|improve this answer
Works great! thank you Julian ... – Steve Oct 8 '12 at 20:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.