I should now grow a beard
November 28th, 2008Because I’ve finally found a use for sed!
sed (a stream editor), along with awk, is one of those Unix command line tools that only beardy types ever seem to know how to use well. Further, the beardies can pretty much teleport to the moon using only a combination of sed, awk, grep and magic (I know someone who wrote a webserver using only dd and shell scripting, although he is bonkers and Italian in addition to beardy).
So anyway, the practical use of sed? Say you have a hypothetical large SQL file which you’re theoretically trying to import into MySQL using the command line. Let’s say, there’s a slight chance that there might be an error in that file, possibly on line 17,633. Opening the file in a text editor and searching for that line is pretty tedious and even simple text editors get pretty slow when you ask them to open a 24Meg file…
Enter sed. Assuming there’s a bug on line 17,633, you’d probably want to display a few lines either side, and this will do it:
sed -n "17630,17640 p" file.sql
Sorted!


You missed out the bit where I am very awesome.
- Sarah @ 29 November 2008funnily enough i had a 122,000ish line CSV open in TextWrangler today and DID need to edit a line around the 14,000 mark
- aaron / tinyblob @ 29 November 2008