Follow me on Twitter for my latest adventures!
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: 115546 times
Plain Text (.txt):
Download link: sed stream editor cheat sheet (.txt)
Downloaded: 33766 times
Microsoft Word 2000 format (.doc):
Download link: sed stream editor cheat sheet (.doc)
Downloaded: 6479 times
Are you interested in sed and unix text editing power tools? Here are three great books on this topic from Amazon:


Facebook
Plurk
more
GitHub
LinkedIn
FriendFeed
Google Plus
Amazon wish list
Comments
Great job. I've added it to http://TechCheatSheets.com
Hey, SR. Thanks so much for adding it to your site :)
Nice post.
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.
please help me.the last output is 1,7,6
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.
anyone have hack for cod4 1,7?
please send me on :
serbiaursus@hotmail.com
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?
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.
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
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
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.
It's just ascii art.
.------. .------. | This | | Just +------+.-----' `------+ Like | `-------'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.
Leave a new comment