6 ms·
> They use linux or OSX. But they don't know awk/sed/bash Am I in the minority of developers then? I don't know awk and sed and I'm honestly not very intereste
by Cyph0n 10y ago
> They use linux or OSX. But they don't know awk/sed/bash
Am I in the minority of developers then? I don't know awk and sed and I'm honestly not very interested in learning them. But bash I definitely agree with. I still use a cheatsheet to get the syntax right because it's weird as hell imo.
- GFK_of_xmaspast 10y agoThere's no reason to use awk or sed when perl exists (a2p and s2p have existed for decades)
- kazinator 10y agoThere is no reason to use perl in situation when awk kicks its butt with clearer, shorter code free of distracting sigils and other line noise Awk is also POSIX standard; a good remaining reason to use it (if it is a feasible alternative for a task) is that a script has to be portable outside of GNU/Linux.
- tripa 10y agoI like Perl a lot better than awk, buy I do agree with the general sentiment of using the language that makes for the clearest code for the task at hand, especially the smaller ones. Which makes me a frequent awk proponent. So I'm surprised at the following part of your comment: > There is no reason to use perl in situation when awk kicks its butt with clearer, shorter code free of distracting author and other line noise In my experience, the shorter ask code tends to be the one with sigils.
- jhbadger 10y agoBut in a lot of ways awk seems way more modern than Perl (Perl 5 at least). You actually have functions with parameters rather than having a weird @_ array that you need to shift values from. Honestly, if I didn't know otherwise, I'd think awk came after Perl.
- vgy7ujm 10y agoFunctions with parameters in a () is already in Perl 5. Search for subroutine signatures. http://perldoc.perl.org/perlsub.html#Signatures http://perldoc.perl.org/perlsub.html#Signatures
- sokoloff 10y agoWorth reading "Area Number Three" on this blog post from Steve Yegge: https://sites.google.com/site/steveyegge2/five-essential-phone-screen-questions https://sites.google.com/site/steveyegge2/five-essential-pho...
- Cyph0n 10y agoIsn't that just a `grep -R [regex pattern]`? Not sure where something like awk or sed fits in to solve such a problem.
- sokoloff 10y agoThe primary point was one of mindset, but the second example in the cited section is a tailor-made sed example: Let's say you're on my team, and I've decided I'm a real stickler for code formatting. But I've got peculiar tastes, and one day I decide I want to have all parentheses stand out very clearly in your code. So let's say you've got a set of source files in C, C++, or Java. Your choice. And I want you to modify them so that in each source file, every open- and close-paren has exactly one space character before and after
- Cyph0n 10y agoWhoops, didn't notice that one. Thanks for linking that post by the way. Great read.
- sokoloff 10y agoMost Yegge blog rants are well worthwhile, IMO. I wish he wrote more of them.
- dgacmu 10y agoY'know - after thinking about it a little, I'd argue that this is a question that could serve a second purpose. The obvious out-of-the box implementations of this in sed/perl/etc. would all fail to properly handle open and close parens in strings and comments. Particularly multi-line comments and strings with escaped quotation marks inside of them. I like sed. I like perl one-liners. I would consider it a mistake to try to do this on a real codebase in a batch manner with just a regexp. You'd be far better off googling to find a source code formatter that includes a real parser, like clang-format.
- robalfonso 10y agoawk and sed are fantastic for command line processing of text. You really should take a look at them. All that said, if you don't find yourself trying to do something in bash and thinking "there must be an easier way" then you're problem sets may just not need them.
- wruza 10y agoedit: comment was about perl, I didn't notice discussion below
- bootload 10y ago"I don't know awk and sed and I'm honestly not very interested in learning them. But bash I definitely agree with." Awk/Sed are optimised for text/data processing.[0] While Bash might work, will the script work on all systems (and version)? [1] awk & predecessor sed are good for one liner programs and suitable for problems that need fast, reliable solutions. reference [0] Opening, closing files; reading, breaking and counting record fields. [1] OS use Bash or Bourne? https://en.wikipedia.org/wiki/Bash_(Unix_shell)#Portability https://en.wikipedia.org/wiki/Bash_(Unix_shell)#Portability
- freehunter 10y agoThen again, sed works differently on different platforms, and awk is not the same as gawk or nawk, both of which have many more features than standard awk. If you're used to the GNU implementation, you might be surprised to find your script doesn't work on a system without the gawk implementation. On Linux, I can use this sed command: sed -i ‘s/^”//’ example.txt That deletes any quotation marks that are at the beginning of a line. It does it in-place, and while you have the option to rename the old file and replace it with a new file with the original name (using "sed -i.bak ‘s/^”//’ example.txt" would move the existing example.txt file to example.txt.bak and write a new one in-place), if you leave out the .bak, it just writes it in-place with no backup file. On OS X, though, that command won't work. You have to specify a backup file, even if it's blank. "sed -i “” ‘s/^”//’ example.txt" would replace the text in-place without a backup. sed -i “.bak” ‘s/^”//’ example.txt would replace the file and move the original to "example.txt.bak". Even with sed and awk, you still have to stop and wonder if it will work cross-platform.
- wcarron 10y agoThis is why I have gripes about the OS X command line. I can't confidently use the scripts I do on Ubuntu/Mint/Debian. Like, get with the program, Apple. It infuriates me and I'm moving entirely off their platform as soon as my Mac kicks the bucket.
- deleted 10y ago[deleted]
- rcdmd 10y agoI don't think you are in the minority, assuming you have a reasonable way to quickly parse text. I think most developers just Google for one-liners or throw something together in Python to solve text-parsing tasks at hand, rather then trying to remember which tool uses which type of regex with which argument.
- dsacco 10y agoIf you're getting along fine without awk then by all means, don't learn it. But just today I had to quickly get a raw list of all US area codes (and only area codes). After a short Google search, I realized the fastest way of downloading and formatting it without having to do a secondary step was this: curl https://raw.githubusercontent.com/kedarmhaswade/cities/master/area-codes.csv | \ awk -F, '{print $1}' \ > ~/area_codes.txt Now, could you use grep? Yeah, sure. But for really quick examples like this - things that lend themselves to it (e.g. a raw CSV with mostly crap you don't need but something you do), this is super fast. Anything more complicated and I'd break out a regex, though.