Earlier quoted context omitted.
Perl? Wow. Is that better than bash, python or even nodejs? Why write in Perl over these? Serious question, was propaghandized to hate Perl.
The same shortcut syntax that people complain about does make perl really handy for one-time tasks where you're iterating on ideas. Lots of features there that make that easy. One example: #!/usr/bin/perl while ( ) { # various processing here # $ARGV is set to either "-" for piped input, or the current filename # $_ is the data of the current line } That ( ) construct accepts data from stdin, redirection or file(s) n…
The Awk Programming Language
91–100 of 159 posts
Re: The Awk Programming Language
#92Earlier quoted context omitted.
Perl? Wow. Is that better than bash, python or even nodejs? Why write in Perl over these? Serious question, was propaghandized to hate Perl.
Perl better? maybe or maybe not. It can be very useful and they are pretty robust. I often found Perl scripts running for years and years without issues at different companies. My main issue with Perl-scripts is that they often are not "readable" by anybody but the original creator. Which of course left the company. (not a fault of Perl itself tough) But your millage may vary and any script can be made (un)readable.
fn print_d(t: &'static impl Display) {Re: The Awk Programming Language
#93I love using Awk, the only thing I miss is that it can't handle complex csv files. Does anyone know how to handle quoted CSV strings like > "foo","bar,baz"
# This function takes a line i.e. $0, and treats it as a line of CSV, breakin
# it into individual fields, and storing them in the passed in field array. It
# returns the number of fields found, 0 if none found. It takes account of CSV
# quoting, and also commas within CSV quoted fields, but doesn't remove them
# from the parsed field.
# use in code like:
# number_of_fields = parse_csv_line($0, csv_fields)
# csv_fields[2] # get second parsed field in $0
function parse_csv_line(line, field, _field_count) {
_field_count = 0
# Treat each line as a CSV line and break it up into individual fields
while (match(line, /(\"([^\"]|\"\")+\")|([^,\"\n]+)/)) {
field[++_field_count] = substr(line, RSTART, RLENGTH)
line = substr(line, RSTART+RLENGTH+1, length(line))
}
return _field_count
}
It's not perfect but gets the job done most of the time and works across all awk implementations.Re: The Awk Programming Language
#94I FINALLY started learning awk in the past couple weeks. I think I was intimidated because awk can be very terse, and there are some default actions that aren't clear when you first start looking at awk scripts. My other problem is that I want to accomplish things, not learn a tool, and it generally takes me a bit longer than it should to decide to actually learn something and not just hack at it. Is it still worth i…
(based on my experience where people who could've benefited from awk for a one-liner dependably reach for sheets/excel rather than something like python or perl)
Re: The Awk Programming Language
#95I was expecting the book, but the page itself says "This page is a placeholder for material related to the second edition of The AWK Programming Language."
It's fine if this is a placeholder page (and an awesome excuse to read talk about AWK here on HN :) ) but I want to be sure that I'm not missing the book itself.
Re: The Awk Programming Language
#96Ok, dumb question: Is the link supposed to link to the actual book (i.e., is the book free and/or open source) or is this just a page of miscellaneous interesting links about the book (which we can pay for, later, when it's published). I was expecting the book, but the page itself says "This page is a placeholder for material related to the second edition of The AWK Programming Language." It's fine if this is a place…
Re: The Awk Programming Language
#97Earlier quoted context omitted.
This is exactly why I moved from AWK to Perl for these quick jobs a couple of years ago. If you stick to an AWK-like subset, Perl is also simple, fast and lightweight. If you want to grow your scripts (and you have a lot of discipline) Perl – in contrast to AWK – gives you enough noose to hang^W^W^W^Wthe tools you need.
Perl? Wow. Is that better than bash, python or even nodejs? Why write in Perl over these? Serious question, was propaghandized to hate Perl.
Re: The Awk Programming Language
#98>I used awk until I learned Python (long ago). For me, awk was yet another example of the "worse is better" approach to things so common in unix. For example, if you make a syntax error, you might get a message like "glob: exec error," rather than an informative message. "Worse is better" is probably a good strategy in business and for getting things done, but still, mediocrity and the sense of entitlement that so often goes with carelessness, sickens me.
[0] https://news.ycombinator.com/item?id=13457265
Long live the Unix Hater's Handbook! (Unix is fine, and so are the criticisms herein. Some of these criticisms have been eclipsed by ongoing development.) https://en.wikipedia.org/wiki/The_UNIX-HATERS_Handbook
Re: The Awk Programming Language
#99I wish awk had support for addressing a range of fields, like from $1 to $7. `cut` supports it, FWIW.
You can always loop through the fields, but it’s a little messy, especially for one-liners
Re: The Awk Programming Language
#100I know lots of people like awk, but I pretend it doesn't exist. Why? Here's my comment on this from 6 years ago[0], >I used awk until I learned Python (long ago). For me, awk was yet another example of the "worse is better" approach to things so common in unix. For example, if you make a syntax error, you might get a message like "glob: exec error," rather than an informative message. "Worse is better" is probably a…