I am now on Twitter! Meet me on Twitter here (my nick is pkrumins.)
Or on Google Buzz and Facebook.
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!
PDF:
Download link: sed stream editor cheat sheet (.pdf)
Downloaded: 37913 times
Plain Text (.txt):
Download link: sed stream editor cheat sheet (.txt)
Downloaded: 18744 times
Microsoft Word 2000 format (.doc):
Download link: sed stream editor cheat sheet (.doc)
Downloaded: 3333 times
Are you interested in sed and unix text editing power tools? Here are three great books on this topic from Amazon:
| < |
Did you like this post? Subscribe here:
If you really enjoyed the post, I'd appreciate a gift from my geeky Amazon book wishlist. Books would make me more educated and I could write even better posts. Thanks! :)

(10 votes, average: 4.1 out of 5)
|
|
|


September 6th, 2007 at 7:14 pm
Great job. I’ve added it to http://TechCheatSheets.com
September 6th, 2007 at 7:57 pm
Hey, SR. Thanks so much for adding it to your site :)
September 21st, 2007 at 1:08 am
[…] Sed cheat sheet Filed under: BSD, Linux, Reference, Solaris — 0ddn1x @ 2007-09-20 22:08:44 +0000 http://www.catonmat.net/blog/sed-stream-editor-cheat-sheet/ […]
February 1st, 2008 at 8:15 pm
Nice post.
April 3rd, 2008 at 11:14 pm
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.
April 3rd, 2008 at 11:16 pm
please help me.the last output is 1,7,6
April 6th, 2008 at 11:50 pm
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 5th, 2008 at 11:35 pm
anyone have hack for cod4 1,7?
please send me on :
serbiaursus@hotmail.com
July 18th, 2008 at 9:54 pm
[…] http://www.catonmat.net/blog/sed-stream-editor-cheat-sheet/ - Peteris Krumins […]
September 1st, 2008 at 12:33 am
[…] my awk and sed cheat sheets might come […]
October 19th, 2008 at 12:03 pm
[…] to Awk learning process. First I went through Bruce Barnett’s sed tutorial; then I created a sed cheat sheet; and finally went through sed one-liners. I could not figure one of the one-liners in the file, so […]
December 14th, 2008 at 11:35 pm
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 24th, 2008 at 12:06 am
[…] have also made a sed cheat sheet that summarizes the whole sed utility. I suggest that you print it before you proceed and keep it […]
April 7th, 2009 at 7:38 am
[…] Sed - Stream Editor - Cheat Sheet […]
April 7th, 2009 at 9:40 pm
[…] Sed Stream Editor Cheat Sheet - Savvy Sed […]
April 15th, 2009 at 2:24 pm
[…] Sed Stream Editor Cheat Sheet - Savvy Sed […]
April 29th, 2009 at 11:50 am
[…] If you are new to sed definteily check out Eric Wendelin’s Get sed savvy Part 1, 2, and 3 Sed - UNIX Stream Editor - Cheat Sheet […]
May 11th, 2009 at 10:23 am
[…] Sed - UNIX Stream Editor - Cheat Sheet - Cheat Sheet utilissima per Sed, con tutte le shortcut in tabella […]
June 22nd, 2009 at 8:05 pm
[…] si, toma una copia de mi cheat sheet, imprímela y metámonos en los […]
July 15th, 2009 at 10:13 am
[…] Sed - Stream Editor - Cheat Sheet - good coders code, great reuse 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! […]
July 19th, 2009 at 12:02 am
[…] hecho una cheat sheet que sumariza toda la herramienta sed. Sugiero que la imprimas antes de seguir y la tengas junto a […]
July 26th, 2009 at 12:00 am
[…] hecho una cheat sheet que sumariza toda la herramienta sed. Sugiero que la imprimas antes de seguir y la tengas junto a […]
December 8th, 2009 at 3:35 pm
[…] An article about sed cheat sheet on catonmat. […]
December 13th, 2009 at 2:11 pm
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 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.