Timeline for What is the difference between sed and awk?
Current License: CC BY-SA 3.0
15 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jun 27, 2022 at 20:19 | comment | added | Dennis Williamson |
The main differences between mine and Daniel Schmidt's are that he includes -E which Mac sed requires to enable extended regexes (and Gnu sed accepts, it also accepts -r ) which allows the use of parens and some other regex chars to be used without escaping. And he uses an improperly unescaped dot which causes the regex to only match numbers which consist of two or more characters (perhaps including a.following space). If he had escaped the dec. point then the number would require one. My regex doesn't have this problem. Neither is completely robust, however, since no anchors are used.
|
|
Jan 12, 2021 at 15:09 | comment | added | pbarney |
FYI, the example from @DanielSchmidt translates Total losses were -1234.56 this month into Total losses were (1234.56) this month for an answer to the "accountants brackets" mentioned in the answer.
|
|
Nov 15, 2018 at 15:49 | comment | added | Dennis Williamson | @jena While there may be something cool about that, it's awful in so many ways I stopped counting. | |
Nov 15, 2018 at 14:09 | comment | added | jena | @Steam Your example sounds like typical use case of awk, for example you can have a look at this cool article. | |
May 8, 2018 at 21:05 | comment | added | Daniel Schmidt | Just an FYI for anyone stumbling across this on a mac, try "sed -E 's/-([0-9]+.[0-9]*)/(\1)/g'" for the first sed example | |
Feb 9, 2014 at 17:39 | history | edited | Dennis Williamson | CC BY-SA 3.0 |
correct error in one-liner, add additional information
|
Aug 20, 2013 at 21:08 | comment | added | Dennis Williamson | library. OTOH, Python and Perl have vast core and 3rd part libs. Sed can handle quite large tasks within its capabilities and, although one could argue that it's Turing complete, it's not very well suited for algorithmic approaches. | |
Aug 20, 2013 at 21:07 | comment | added | Dennis Williamson | That is a blanket statement with insufficient qualifiers. However, there is a point at which Python or Perl should be used instead of AWK. There are tasks at which a compiled language would be better. I would use AWK for textual data that appears in rows and columns. AWK is pretty much limited to one or two dimensional arrays (Python and Perl support much more complex data structures by comparison) and has really no library support. Not that it can't be done, but there just really isn't any established... | |
Aug 20, 2013 at 20:09 | comment | added | Steam | A link says - vectorsite.net/tsawk_1.html - "There are, however, things that Awk is not. It is not really well suited for extremely large, complicated tasks." Now, how "large" a task can awk handle ? How does sed compare in that respect ? | |
Aug 20, 2013 at 19:56 | comment | added | Steam | @DennisWilliamson - What would be most useful to an ETL developer ? ETL or Extract Transform and Load is a data-warehousing term. Put crudely, the job involves EXTRACTION of data from different disparate sources (such as DB's, excel files, csv files etc), TRANSFORMATION of the same and then LOADING into a datawarehouse (DW) for analysis, finding patterns in data, or just historical records. eg. End use of a DW - Algorithms applied to a DW of a grocery store which has data from the past 10 years might reveal that people who tend to buy apples also buy oranges or something similar. | |
Aug 20, 2013 at 19:52 | comment | added | Dennis Williamson | @blasto: My recommendation is to learn both but with more emphasis on awk. Lots of the regular expression stuff applies to both (and other tools and languages). Use sed for simpler stuff and try to avoid the complex things. It's really cool that you can do loops and branches in sed, but the resulting command lines are complex and hard to read. The answer to your question really depends on what you're doing. | |
Aug 20, 2013 at 18:24 | comment | added | Steam | @DennisWilliamson - Am I at a disadvantage if I only learn awk ? Is awk far more commonly used than sed ? | |
Oct 27, 2009 at 21:58 | comment | added | Dennis Williamson |
To see some examples of pushing the boundaries of sed : sed.sourceforge.net/#scripts
|
|
Oct 27, 2009 at 20:46 | vote | accept | Rachel | ||
Oct 27, 2009 at 17:53 | history | answered | Dennis Williamson | CC BY-SA 2.5 |