4 ms·
Awk & SED I have a hard time think about one without the other. I think they should be married.
by baldfat 12y ago
Awk & SED I have a hard time think about one without the other. I think they should be married.
- deleted 12y ago[deleted]
- coliveira 12y agoI use awk often, but rarely use sed, so I think they don't need to be always together.
- AdmiralAsshat 12y agoAwk & Sed are labeled as the following in my mind: - Awk: That thing I use when I need to grep for something over more than one line and/or do some basic transformations. - Sed: That thing with the painful syntax for doing ridiculously complicated regex substitutions. With that said, I find sed much more difficult to use than awk and generally try to avoid it if I can. I'm even prone to just opening the file in vim and executing the replace command through that rather than using sed.
- seanp2k2 12y agoDoes noting that you don't have to use / as the separator help with the syntactical pain? I personally always use |, since I'm unlikely to be using that for a pattern. Example: grep foo somefile | sed 's|/path/to/some/file|/new/path|g' Lot nicer than all those picket fences \/\/\/
- a3n 12y agoI would use sed for transformations (simple or complex) where I only care about one transformation (even though you can do multiple): Does the current line match this pattern? Change it to this other thing and move on the next line. I would use awk when there are a handful or more of potential transformations: Does the current line match any of these multiple patterns? Do the action that's defined for each of the patterns, then move on to the next line. If I need to do multiple transformations, and still want to use sed, I find it easiest to create a chain of single sed transformations, piped together. Somewhere in that area a shift to awk (or python) becomes justified.
- simpleigh 12y agoI found sed great for messing around with SVN repository dumps. Delete a few lines here to remove the commit that added a directory... change a few paths to pretend the files in that directory had always been somewhere else... add a few lines somewhere else. Sed scripts are a quick way to automate simple edits to large files.
- cbd1984 12y agoIf you view the Unix shell as a language unto itself, awk and sed are both higher-level functions in that language, married via the use of pipelines (concatenative programming without a stack). http://en.wikipedia.org/wiki/Concatenative_programming_language http://en.wikipedia.org/wiki/Concatenative_programming_langu...
- jnazario 12y agoat least in the awks built into osx and debian have sub and gsub (and gawk adds gensub). sub(r, t, s) substitutes t for the first occurrence of the regular expression r in the string s. If s is not given, $0 is used. gsub same as sub except that all occurrences of the regular expression are replaced; sub and gsub return the number of replacements.
- dfkf 12y agoThey are like Dogar and Kazon. http://www.youtube.com/watch?v=NzvySzw_-O0&t=112 http://www.youtube.com/watch?v=NzvySzw_-O0&t=112