sed as a superman, the unix stream editor

I present to you my cheat sheet of sed, the Superman of stream editing! It has come handy 101 times for me because sed is not what I use daily and after some time of not using the sed commands tend to fade away from my mind and I have to review them quickly. This cheat sheet is ideal for that!

You can't really be a good hacker if you don't know this tool. I always love to think of various situations where knowing many, many different tools makes you the ultimate guru.
Suppose you had a situation where you were on a box which had some problems and the only tool available to you was sed, and you had to fix a configuration file problem really quickly or bad, bad things would happen. If you never knew sed, you'd be in deep trouble because it can't be learned from the man page, because it only lists all the commands and you have no understanding how the commands work.

When I first learned sed, I remember the joy when I understood how it worked, that it operated on input stream, output stream, pattern space and hold buffer. Once you know this, the rest can be understood from the man page, but before that, I doubt it.

If you want to learn the sed editor I recommend this wonderful tutorial and these books.

This sed cheat sheet contains:

  • command line summary
  • command description, if they take single address or pattern, or a range of addresses, and what they modify (input stream, output stream, pattern space or hold buffer)
  • command line argument summary
  • extensions
  • short summary of adderss range format

If you notice any inaccuracies, mistakes or see that I have left something out, comment on this page, please!

Download Sed Stream Editor Cheat-Sheet

PDF:
Download link: sed stream editor cheat sheet (.pdf)
Downloaded: 132738 times

Plain Text (.txt):
Download link: sed stream editor cheat sheet (.txt)
Downloaded: 37535 times

Microsoft Word 2000 format (.doc):
Download link: sed stream editor cheat sheet (.doc)
Downloaded: 7267 times

Are you interested in sed and unix text editing power tools? Here are three great books on this topic from Amazon:

Comments

September 06, 2007, 19:14

Great job. I've added it to http://TechCheatSheets.com

September 06, 2007, 19:57

Hey, SR. Thanks so much for adding it to your site :)

February 01, 2008, 20:15

Nice post.

stephen Permalink
April 03, 2008, 23:14

i've got problem on sed, which is i hv to change the line with colon to comma, and also change some order of the line,but the line is rili long. its like 1:2:3:4:5:6:7. i hv to only left 1:6:7. and also hv to change the order to 1:7:6.
how can i do that and write into script.please gv me some hint.

stephen Permalink
April 03, 2008, 23:16

please help me.the last output is 1,7,6

April 06, 2008, 23:50

Stephen, not sure I understand your question...
You can try doing 'sed -e 's/:/,/g' to change colons into commas. It's harder to change the order.
AWK language seems more appropriate, as you can specify split and field seperators, etc.

July 05, 2008, 23:35

anyone have hack for cod4 1,7?
please send me on :
serbiaursus@hotmail.com

zorg Permalink
December 14, 2008, 23:35

On the second page, it says that you can specify a label with a text string followed by a colon. Is that really true? It seems like the opposite of specifying a label. Shouldn't it read "... text string following a colon ..." instead?

December 13, 2009, 14:11

I'm having to open like 8 pages on your site to get your sed tips.. It'd be much easier for people if you created a master sed jump off point.

I feel the same way about sed as you, modifying streams mid-stream is just freaking awesome.

Check this out:

G=$'\33[H\33[2J'
A=$'\a'

G will reset and clear the screen, A will cause a bell, but only if they are output to the tty.

Using sed I can tail a log file like a php_error.log file and when sed sees a special keyword appear in the output from tail it replaces it with G or A.

tail -f php_error.log | sed -u -e "s/AATPUTCLS/${G}/g"

And in my php file I might add

error_log('AATPUTCLS');

which would send that to the php_error.log and if it is being output via tail then sed resets the screen making it easy to focus in on code segments.

I hope you have some cool stuff on sed.. it's one tough cookie to figure out, but soo worth it. I use it alot in my various functions for my bash_profile.

sadarat Permalink
October 20, 2010, 06:38

Hey if any on has these charts on these commmands like

SED, AWK, GREP etc please farward hem on my mail
getnayab@gmail.com
thank you

November 16, 2010, 15:54

Nice layout. Asciidoc is nice to maintain the various output formats. It support tables that look descent in text, pdf, html output.

Just noticed in your sed cheat sheet, there is no -V only --version, like --help.

http://www.gnu.org/software/sed/manual/sed.html

surya Permalink
December 05, 2012, 09:05

Your plain text documnet has a very nice layout.
How did you create those nice tables in text? I am very curious to know that.

January 02, 2013, 17:39

It's just ascii art.

         
              .------.
.------.      | This |
| Just +------+.-----'
`------+ Like  |
       `-------'
samantha Permalink
March 01, 2013, 00:21

Well, I am considered a quite good hacker. But I frankly consider having to learn a bunch of different languages to do my work with little or no commonality a waste of brainpower. There is a sweet spot between a tool/process in a pipeline on series of commands and another language. I don't think our profession will advance until there is one core language and everything else expressible in that. But maybe I got warped playing with a Symbolics machine in my formative years. :)

That you even have to dig out a cheat sheet for X may be a sign that X just isn't good enough and perhaps shouldn't live as a separate thing.

Drew Marold Permalink
July 18, 2013, 13:56

Until that one grand unified thing comes along though you've got to work with what's out there. I'm a release engineer, so I have to know a wide variety of tools because you never know what you're going to encounter. I can write scripts in shell, sed, awk, perl, python, expect, dabble in C, and read & understand a couple more languages. That breadth of knowledge makes me very in demand. But I still keep cheat sheets & O'Reilly books on hand because I don't use them all every day, and sometimes it's hard to remember the exact specifics. It's kind of the opposite of the old saying "When all you have is a hammer, everything looks like a nail." I have a well stocked toolbox that lets me solve problems with a tool that matches the problem space.

April 16, 2014, 13:50

Ok really good news

April 16, 2014, 13:50

Ok really good news

April 27, 2014, 11:59

I must say indeed an awesome post and just loved the whole read. Looking forward to such more awesome reads !!
Manabadi Inter Results

Inter First Year Results

Inter Results 2014

2014 Inter Results

1st year results 2014

2014 Intermediate First year Results

May 07, 2014, 10:48

Ok it might be success

May 12, 2014, 04:36

Really great article shared by you and your team. I always visited your blog. Thanks for sharing this type of article. The articles is so good to view of technical point. Just these are my androids apps for PC blog. You can download these by using our tutorials and guides.Thanks.
Download Free Wechat For PC
Free Download Kik Messenger For PC
Download Free WhatsApp For PC
Free WhatsApp For PC
Free Download Deer Hunter 2014 For PC
Free Download BBM For PC.

Very Nice article...Loved it from top to bottom..Every single letter of this article has been written with utmost professionalism...

Twitter Mute Button

Lok Sabha Election 2014

Firefox 29 Design.

May 19, 2014, 10:23

Very Nice article...Loved it from top to bottom..Every single letter of this article has been written with utmost professionalism... tn sslc results 2014
10th result 2014
sslc results 2014
tamilnadu 10th results .

May 23, 2014, 07:05
May 23, 2014, 07:05
June 04, 2014, 16:53

Great job.

June 05, 2014, 08:48

Ok it is nice presented and thanks

June 07, 2014, 01:41

Thanks for sharing this information. Very informative and also helpful
Caribbean Jobs
Legal Jobs
Mobile option Caribbean Jobs

Thanks again

smith Permalink
June 08, 2014, 06:49
mikerag Permalink
June 12, 2014, 07:48

This is really a great read for me. Thank you for publishing articles having a great insight stimulates me to check more often for new write.
fathers day quotes
father's day quotes
happy fathers day quotes
fathers day quotes from daughter
fathers day messages...

June 13, 2014, 06:53

Is really important news

faheen Permalink
June 22, 2014, 04:51

Ramadan Wallpaper
Ramadan Wallpaper HD Download
Ramadan Wallpaper 2014
Ramadan Wallpaper 2014 Download
Ramadan Wallpaper 2014 HD Images
Ramadan Wallpaper 2014 Images
Ramadan Wallpaper quotes
Ramadan wallpaper greetings
Ramadan wallpaper 2014 greetings
Ramadan Wallpaper 2014 quotes
Ramadan Kareem 2014 images
Ramadan Kareem Mubarak Images
Ramadan Kareem Mubarak 2014 images
Ramadan Screen Saver 2014 download
Ramadan Mubarak images
Ramadan images 2014
Ramadan Mubarak greetings
Wish you happy Ramadan 2014
Happy Ramadan Wallpaper 2014
Ramadan wallpaper 2014
Wish you happy Ramadan 2014
ramadan Hd wallpaper 2014
Wish you happy Ramadan wallpaper 2014
Ramadan 2014 images
Ramadan 2014 pictures
wish you happy Ramadan 2014 images
Wish you happy Ramadan 2014 pictures
Happy ramadan 2014 wallpaper
Ramadan Kareem 2014 Wallpaper
Ramadan Mubarak 2014 wallpaper
Wallpaper Ramadan 2014
Ramadan HD wallpaper
Ramadan 2014 HD wallpaper
wish you Ramadan 2014 HD wallpaper
Happy Ramadan HD wallpaper
Happy Ramadan 2014 HD wallpaper
Wish you Ramadan HD wallpaper Download 2014
Ramadan HD wallpaper Download 2014
Ramadan HD wallpaper 2014 Download
Ramadan HD wallpaper 1080p
Ramadan 2014 HD wallpaper 1080p
Best Ramadan 2014 HD wallpaper
Top 10 Ramadan 2014 HD wallpaper
Best Collections Of Ramadan 2014 HD wallpaper
Ramadan 2014 HD wallpaper For Android
Ramadan 2014 best Screensaver download
Ramadan 2014 Screensaver download
screensaver download for mobile Ramadan 2014
Ramadan 2014 HD Screensaver Download
Ramadan 2014 download best screen saver
Screensaver for 2014 ramadan
Ramadan mubarak screensaver download
Ramadan mubarak 2014 best screen saver
Ramadan Kareem Mubarak 2014 best screen saver
Ramadan mubarak 2014 best screen saver
screen saver 2014 download free for android
Ramadan Kareem Mubarak Greetings 2014
Best Collections of Ramadan 2014 Greetings
Best Collections of Ramadan 2014 Greetings
Top Collections of Ramadan 2014 Greetings
Ramadan 2014 Greetings
Ramadan 2014 Greetings Free
Ramadan 2014 Greetings Kareem best
Best Collections of Ramadan 2014 Kareem Greetings
Best Collections of Ramadan 2014 Kareem Greetings
Best Collections of Ramadan 2014 kareem greetings
Top Ramadan 2014 wallpapers
Top Ramadan 2014 pictures
Top ramadan 2014 pictures for pc
Top ramadan 2014 Wallpaper for Android
Ramadan 2014 best softwares
Ramadan 2014 Best Images of Desktop
Ramadan 2014 best pictures for desktop
ramadan 2014 collection of Hd wallpaper
Ramadan 2014 Best collections
Ramadan 2014 top Hd wallpaper
Ramadan 2014 in uk
When Ramadan 2014 in Uk
ramadan 2014 in United Kingdom
When Ramadan 2014 in United States
When ramadan 2014 in America
Ramadan date in uk
Ramadan date in uk
Ramadan facts in united kingdom
Ramadan date in France
Ramadan 2014 in france
Ramadan 2014 date in france
Ramadan 2014 date in Frace country
Happy Ramadan 2014 best wallpaper
Ramadan Wallpaper best collections
Ramadan Kareem Wallpaper collections
wish you happy Ramadan wallpaper 2014
happy Ramadan wallpaper 2014
wish you happy Ramadan Hd wallpaper
Happy Ramadan 2014 HD wallpaper
Hd Ramadan wallpaper 2014
Wallpaper 2014 Hd in Ramadan
Ramadan wallpaper 2014 for Desktop Background
Best Islamic Ramadan wallpaper 2014
Wallpaper 2014 for facebook Cover
Best Wallpaper 2014 Download
Ramadan HD wallpaper 2014 Download
When ramadan in India 2014
Ramadan in India 2014
Ramadan in India 2014
Ramadan Kareem Greetings
Ramadan kareem Mubarak Greetings
Ramadan kareeem 2014 Greetings
Ramadan 2014 kareem Greetings
Ramadan 2014 kareem greetings
Ramadan Kareem Mubarak 2014
Ramadan kareem Mubarak 2014
Ramadan kareem Mubarak 2014
Ramadan Kareem greetings 2014
Ramadan Kareem greetings 2014
Ramadan Kareem greetings 2014
Ramadan Kareem greetings 2014
Ramadan Kareem greetings 2014
Ramadan Mubarak Greetings 2014
Ramadan Mubarak Greetings 2014
Ramadan Mubarak Greetings 2014
Ramadan Mubarak Greetings 2014
Ramadan Mubarak Greetings 2014
Ramadan Mubarak Greetings 2014
Ramadan Mubarak Greetings 2014
Ramadan Mubarak Greetings 2014
Ramadan Mubarak Greetings 2014
Ramadan Mubarak Greetings 2014
Ramadan Mubarak Greetings 2014
Inspirational pictures of ramadan 2014
Inspirational pictures of ramadan 2014
Inspirational pictures of ramadan 2014
Inspirational pictures of ramadan 2014
Inspirational pictures of ramadan 2014
Inspirational pictures of ramadan 2014
Inspirational pictures of ramadan 2014
Inspirational pictures of ramadan 2014
Inspirational pictures of ramadan 2014
Inspirational pictures of ramadan 2014
Ramadan 2014 Wallpaper and Mubarak pics
Ramadan 2014 Wallpaper and Mubarak pics
Ramadan 2014 Wallpaper and Mubarak pics
Ramadan 2014 Wallpaper and Mubarak pics
Ramadan 2014 Wallpaper and Mubarak pics
Ramadan 2014 Wallpaper and Mubarak pics
Ramadan 2014 Wallpaper and Mubarak pics
Ramadan 2014 Wallpaper and Mubarak pics
Ramadan 2014 Wallpaper and Mubarak pics
Ramadan 2014 Wallpaper and Mubarak pics
Ramadan 2014 Wallpaper and Mubarak pics
Awesome Post Ramadan Wallpaper Ramadan Wallpaper HD Download Ramadan Wallpaper 2014 Ramadan Wallpaper 2014 Download Ramadan Wallpaper 2014 HD Images Ramadan Wallpaper 2014 Images Ramadan Wallpaper quotes Ramadan wallpaper greetings Ramadan wallpaper 2014 greetings Ramadan Wallpaper 2014 quotes Ramadan Kareem 2014 images Ramadan Kareem Mubarak Images Ramadan Kareem Mubarak 2014 images Ramadan Screen Saver 2014 download Ramadan Mubarak images Ramadan images 2014 Ramadan Mubarak greetings Wish you happy Ramadan 2014 Happy Ramadan Wallpaper 2014 Ramadan wallpaper 2014 Wish you happy Ramadan 2014 ramadan Hd wallpaper 2014 Wish you happy Ramadan wallpaper 2014 Ramadan 2014 images Ramadan 2014 pictures wish you happy Ramadan 2014 images Wish you happy Ramadan 2014 pictures Happy ramadan 2014 wallpaper Ramadan Kareem 2014 Wallpaper Ramadan Mubarak 2014 wallpaper Wallpaper Ramadan 2014 Ramadan HD wallpaper Ramadan 2014 HD wallpaper wish you Ramadan 2014 HD wallpaper Happy Ramadan HD wallpaper Happy Ramadan 2014 HD wallpaper Wish you Ramadan HD wallpaper Download 2014 Ramadan HD wallpaper Download 2014 Ramadan HD wallpaper 2014 Download Ramadan HD wallpaper 1080p Ramadan 2014 HD wallpaper 1080p Best Ramadan 2014 HD wallpaper Top 10 Ramadan 2014 HD wallpaper Best Collections Of Ramadan 2014 HD wallpaper Ramadan 2014 HD wallpaper For Android Ramadan 2014 best Screensaver download Ramadan 2014 Screensaver download screensaver download for mobile Ramadan 2014 Ramadan 2014 HD Screensaver Download Ramadan 2014 download best screen saver Screensaver for 2014 ramadan Ramadan mubarak screensaver download Ramadan mubarak 2014 best screen saver Ramadan Kareem Mubarak 2014 best screen saver Ramadan mubarak 2014 best screen saver screen saver 2014 download free for android Ramadan Kareem Mubarak Greetings 2014 Best Collections of Ramadan 2014 Greetings Best Collections of Ramadan 2014 Greetings Top Collections of Ramadan 2014 Greetings Ramadan 2014 Greetings Ramadan 2014 Greetings Free Ramadan 2014 Greetings Kareem best Best Collections of Ramadan 2014 Kareem Greetings Best Collections of Ramadan 2014 Kareem Greetings Best Collections of Ramadan 2014 kareem greetings Top Ramadan 2014 wallpapers Top Ramadan 2014 pictures Top ramadan 2014 pictures for pc Top ramadan 2014 Wallpaper for Android Ramadan 2014 best softwares Ramadan 2014 Best Images of Desktop Ramadan 2014 best pictures for desktop ramadan 2014 collection of Hd wallpaper Ramadan 2014 Best collections Ramadan 2014 top Hd wallpaper Ramadan 2014 in uk When Ramadan 2014 in Uk ramadan 2014 in United Kingdom When Ramadan 2014 in United States When ramadan 2014 in America Ramadan date in uk Ramadan date in uk Ramadan facts in united kingdom Ramadan date in France Ramadan 2014 in france Ramadan 2014 date in france Ramadan 2014 date in Frace country Happy Ramadan 2014 best wallpaper Ramadan Wallpaper best collections Ramadan Kareem Wallpaper collections wish you happy Ramadan wallpaper 2014 happy Ramadan wallpaper 2014 wish you happy Ramadan Hd wallpaper Happy Ramadan 2014 HD wallpaper Hd Ramadan wallpaper 2014 Wallpaper 2014 Hd in Ramadan Ramadan wallpaper 2014 for Desktop Background Best Islamic Ramadan wallpaper 2014 Wallpaper 2014 for facebook Cover Best Wallpaper 2014 Download Ramadan HD wallpaper 2014 Download When ramadan in India 2014 Ramadan in India 2014 Ramadan in India 2014 Ramadan Kareem Greetings Ramadan kareem Mubarak Greetings Ramadan kareeem 2014 Greetings Ramadan 2014 kareem Greetings Ramadan 2014 kareem greetings Ramadan Kareem Mubarak 2014 Ramadan kareem Mubarak 2014 Ramadan kareem Mubarak 2014 Ramadan Kareem greetings 2014 Ramadan Kareem greetings 2014 Ramadan Kareem greetings 2014 Ramadan Kareem greetings 2014 Ramadan Kareem greetings 2014 Ramadan Mubarak Greetings 2014 Ramadan Mubarak Greetings 2014 Ramadan Mubarak Greetings 2014 Ramadan Mubarak Greetings 2014 Ramadan Mubarak Greetings 2014 Ramadan Mubarak Greetings 2014 Ramadan Mubarak Greetings 2014 Ramadan Mubarak Greetings 2014 Ramadan Mubarak Greetings 2014 Ramadan Mubarak Greetings 2014 Ramadan Mubarak Greetings 2014 Inspirational pictures of ramadan 2014 Inspirational pictures of ramadan 2014 Inspirational pictures of ramadan 2014 Inspirational pictures of ramadan 2014 Inspirational pictures of ramadan 2014 Inspirational pictures of ramadan 2014 Inspirational pictures of ramadan 2014 Inspirational pictures of ramadan 2014 Inspirational pictures of ramadan 2014 Inspirational pictures of ramadan 2014 Ramadan 2014 Wallpaper and Mubarak pics Ramadan 2014 Wallpaper and Mubarak pics Ramadan 2014 Wallpaper and Mubarak pics Ramadan 2014 Wallpaper and Mubarak pics Ramadan 2014 Wallpaper and Mubarak pics Ramadan 2014 Wallpaper and Mubarak pics Ramadan 2014 Wallpaper and Mubarak pics Ramadan 2014 Wallpaper and Mubarak pics Ramadan 2014 Wallpaper and Mubarak pics Ramadan 2014 Wallpaper and Mubarak pics Ramadan 2014 Wallpaper and Mubarak pics oHack Anna University Paper Valuation Anna University result 2014 Thanks for sharing

June 27, 2014, 05:49

Truly agree so maybe look he help

June 30, 2014, 09:41

It is so amazing idea

June 30, 2014, 11:33

I agree that is so awesome

July 03, 2014, 07:12

Ok it seems to be profits

July 03, 2014, 09:11

That will be special help

July 05, 2014, 13:37

Ok it seems to be good

July 16, 2014, 12:23

Thank You For Sharing This Excellent Post,
Friendship Day 2014 Quotes
Happy Friendship Day Images
Thank You For Sharing.

July 23, 2014, 03:18

Thank You For Sharing This Excellent Post

friendship day sms
friendship day sms
friendship day sms
...

sanchit Permalink
July 25, 2014, 21:54

Hey its great post really enjoyed this one i found this on google ,i think there are still websmasters who provide quality contents to the reader and hope to come back soon and by the way Eid Mubarak Wishes
Eid Mubarak Sms in Hindi
Eid Mubarak sms In English
Eid Mubarak sms in Urdu
Eid Mubarak Wallpapers
Eid Mubarak Greetings
Eid Mubarak cardsto all of you also you can check Happy eid Mubarak 2014
really a great stuff

sanchit Permalink
July 25, 2014, 21:54

Hey its great post really enjoyed this one i found this on google ,i think there are still websmasters who provide quality contents to the reader and hope to come back soon and by the way Eid Mubarak Wishes
Eid Mubarak Sms in Hindi
Eid Mubarak sms In English
Eid Mubarak sms in Urdu
Eid Mubarak Wallpapers
Eid Mubarak Greetings
Eid Mubarak cardsto all of you also you can check Happy eid Mubarak 2014
really a great stuff

fuyt6t Permalink
July 28, 2014, 16:59

i am great admire of your articles
friendship day 2014
friendship day sms 2014
friendship day sms

thanks for awesome articles

fuyt6t Permalink
July 28, 2014, 16:59

i am great admire of your articles
friendship day 2014
friendship day sms 2014
friendship day sms

thanks for awesome articles

Leave a new comment

(why do I need your e-mail?)

(Your twitter name, if you have one. (I'm @pkrumins, btw.))

Type the first letter of your name: (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.

Advertisements