Live data from Hacker News

How to Clean Text Data at the Command Line

ezzeddinabdullah.com

21–30 of 53 posts

Re: How to Clean Text Data at the Command Line

#21

Earlier quoted context omitted.

brew install coreutils Lot less complexity than running things in docker.

Was just about to say. What text editing powerhouse from Linux (sed, awk, grep etc.) are not available on Mac? The answer is: none.

    "Able to install packages"
Hmmm no that don't look as good on my resume as "autodidact docker wizard"

There's something to be said for the cool-new-tech driven approach, when it comes to resume building.

Re: How to Clean Text Data at the Command Line

#22

I... am... just like baffled at why Docker is used. Are any of these like not normal unix utilities? What dependencies are you pulling in after GNU/Linux... which is where CONTAINERS come from? I'm even only even putting "GNU" here because it's literally every fucking Linux distro on the planet containing the utilities referenced. Is it common place now-a-days to bloat a docker image with text data or something? Is d…

Docker 'can' be used as a way to provide a shell which has a consistent set of programs installed. (As a bonus, using Docker this way let's you avoid 'polluting' the host OS with various packages). Sure, this case where it's just coreutils + csvlookup, the benefit for the added abstractions isn't so great. Using docker like this makes more sense if there are more dependencies. (Maybe it's just easier to say "use dock…

No. I’m sorry but I disagree in this case. These tools are literally installed on every posix machine on the planet. The whole point here is that there are no dependencies this is the “system.” It’s like trying to explain how an engine works by only looking at the turbo, “Oh yeah, gotta have a turbo or your car won’t drive.” ... You mean I gotta have an engine or I can’t even use a turbo?

The whole point of my post is that running a container otecshstration system to accomplish any of this, for someone new, is insane. It is absolutely 100% only adding complexity and making things more confusing. How many people will not realize these utilities are on every computer they use? How long until someone poisons these repacked uselessly opaque versions? This makes things easier for no one and only furthers to complicate things by adding unnecessary complexity.

If someone is on a Mac, then they are now running a Linux VM, then running containers, then logging into said fucked up environment and then finallly... running... awk?

macOS -> Linux -> Container Runtime -> SSH-> finally use awk, sed, head, or anything else. Why stop there? We can probably then start up Qemu from a container, boot MacOS, and then simply repeat the process for maximum usefulness.

Re: How to Clean Text Data at the Command Line

#23
I’ll probably catch a lot of flack but a lot of criticism in these comments for the author who finished something. It’s easy to sit in the cheap seats and cast stones, but this guy made something that works, and you can always make your own if you know better without tearing down the work of others.

Re: How to Clean Text Data at the Command Line

#24

Earlier quoted context omitted.

brew install coreutils Lot less complexity than running things in docker.

Was just about to say. What text editing powerhouse from Linux (sed, awk, grep etc.) are not available on Mac? The answer is: none.

There are some rather archaic behaviors of the versions of these tools that come by default on MasOSX.

For instance, on a mac the 'sed' command doesn't understand the difference between space and tab

https://stackoverflow.com/questions/40311339/using-sed-on-ma...

Re: How to Clean Text Data at the Command Line

#25
post #2

It seems lots of people's knowledge of awk is limited to printing fields, and they'll happily chain awk with a bunch of grep and sed when a single awk invocation would do the job without fuss. For instance, TFA uses awk '{print $1","$2}' | sed '1i count,word' when you can just add a BEGIN block: awk 'BEGIN { print "count,word" } { print $1","$2 }'

I beg to differ. I did a lot of csv wrangling on Unix. Csv is a beast. My tools of choice ultimately was miller, an absolutely underrated tool:

https://github.com/johnkerl/miller

Re: How to Clean Text Data at the Command Line

#26
post #2

It seems lots of people's knowledge of awk is limited to printing fields, and they'll happily chain awk with a bunch of grep and sed when a single awk invocation would do the job without fuss. For instance, TFA uses awk '{print $1","$2}' | sed '1i count,word' when you can just add a BEGIN block: awk 'BEGIN { print "count,word" } { print $1","$2 }'

I beg to differ. I did a lot of csv wrangling on Unix. Csv is a beast. My tools of choice ultimately was miller, an absolutely underrated tool: https://github.com/johnkerl/miller

Oo, I've not come across this one before. Looks useful! In a similar vein of CSV tools that seem to be underrated, I recently came across Daff which does excellent tabular diffs.

https://github.com/paulfitz/daff

Re: How to Clean Text Data at the Command Line

#27
post #2

It seems lots of people's knowledge of awk is limited to printing fields, and they'll happily chain awk with a bunch of grep and sed when a single awk invocation would do the job without fuss. For instance, TFA uses awk '{print $1","$2}' | sed '1i count,word' when you can just add a BEGIN block: awk 'BEGIN { print "count,word" } { print $1","$2 }'

Speaking of AWK, is there a more succinct version of the AWK programming language book that I can use for learning? https://ia802309.us.archive.org/25/items/pdfy-MgN0H1joIoDVoI...

On mobile; pardon the link format.

https://m.youtube.com/watch?v=43BNFcOdBlY

In an afternoon, you can learn enough to be more than dangerous.

The presenter drafted up a set of (easy, yet practical) companion exercises and a pt2 video with his own answers. I cannot recommend this talk enough.

Although I hadn't the opportunity to put the knowledge to use and have since forgotten it (i don't work in tech), i find comfort in knowing i can reacquire the power of awk even sooner than the already-short first time around.

Re: How to Clean Text Data at the Command Line

#28
post #6

Earlier quoted context omitted.

I was also baffled. However, if you follow the link to the "why we use docker" post you'll see the author is using a Mac and had difficulty before while following instructions written for Linux. Data scientists using Macs for everything and sometimes needing to run Linux in a container to get work done is more common than you might think.

brew install coreutils Lot less complexity than running things in docker.

Some programs have different flags and behaviors between Mac OS and linux. This has bitten me quite a few times. Even on Linux there are often competing versions (BSD and GNU version might have different flags for example).

Re: How to Clean Text Data at the Command Line

#29
post #2

It seems lots of people's knowledge of awk is limited to printing fields, and they'll happily chain awk with a bunch of grep and sed when a single awk invocation would do the job without fuss. For instance, TFA uses awk '{print $1","$2}' | sed '1i count,word' when you can just add a BEGIN block: awk 'BEGIN { print "count,word" } { print $1","$2 }'

Or do the case-conversion, minimum word-length restriction, and counting in awk itself, here using associative arrays: awk 2 if(length($i)>2) count[$i]++ } }; END{ # report for(word in count) printf( "%-20s %i\n", word, count[word]) } ' | sort -k2nr -k1 This omits the header (can be trivially added). The external sort can be internalised in gawk using asort(), or by printing to sort via a command: cmd="print -2kr -k1…

When you have such a large awk script, you may as well also demonstrate that Awk is a “real scripting language” by putting it into its own script with a `#!/usr/bin/awk -f` shebang line. Much easier to edit than trying to get your shell to do it. (Unless you’re using a fancy editing shell like Emacs’ shell mode; but at that point, why would you need Awk? You probably know far better how to use your own shell-runtime’s text-manipulation primitives.)

Re: How to Clean Text Data at the Command Line

#30
post #4

Earlier quoted context omitted.

I was also wondering why it starts with docker. But since this post is targeted for data science or becoming data science folk maybe the idea is to also support windows users?

Would it not work in WSL though? If you wanted windows support.

Yep, they all come with WSL, since you basically install Ubuntu (or another WSL-compatible distro).
Post reply on HN