Useful Unix commands for data science
gregreda.com
Useful Unix commands for data science
1–10 of 108 posts
Re: Useful Unix commands for data science
#2Instead this is a set of basic examples of bog-standard tools that every newbie *nix user should be already familiar with: cat, awk, head, tail, wc, grep, sed, sort, uniq
Re: Useful Unix commands for data science
#3One thing I find odd that you have to drop to a full language (awk, perl etc) to sum a column of numbers. Am I missing a utility?
echo "1\n2\n3\n" | sum # should print 6 with hyphothetical sum command
I suppose more generally you could have a 'fold initial op' and: echo "1\n2\n3\n4\n" | fold 0 + # should print 10
echo "1\n2\n3\n4\n" | fold 1 \* # should print 24
But I guess at that point you're close enough to using awk/perk/whatever anyway. Which probably answers my question.Re: Useful Unix commands for data science
#4 cat data.csv | awk -F "|" '{ sum += $4 } END { printf "%.2f\n", sum }'
From that command, it's unclear whether the sum will be accurate, it depends on the inputs and on the precision of awk. See (D.3 Floating-Point Number Caveats): http://www.delorie.com/gnu/docs/gawk/gawk_260.htmlRe: Useful Unix commands for data science
#5http://en.wikibooks.org/wiki/Ad_Hoc_Data_Analysis_From_The_U...
Re: Useful Unix commands for data science
#6I like slicing and dicing with awk, grep and friends too. One thing I find odd that you have to drop to a full language (awk, perl etc) to sum a column of numbers. Am I missing a utility? echo "1\n2\n3\n" | sum # should print 6 with hyphothetical sum command I suppose more generally you could have a 'fold initial op' and: echo "1\n2\n3\n4\n" | fold 0 + # should print 10 echo "1\n2\n3\n4\n" | fold 1 \* # should print…
echo "1\n2\n3\n+\n+\np\n" | dc -
Or, a little more legibly: > dc
1
2
3
+
+
p
6
[Edited to fix bug]Not sure how to automate this to sum 1000 values without needing to explicitly insert 999 + signs, though. Haven't explored dc in depth myself yet. There's probably some way to do it with a macro or something, but it may not be pretty.
Re: Useful Unix commands for data science
#7Re: Useful Unix commands for data science
#8Get-Content .\data.csv | %{[int]$total+=$_.Split('|')[3]; } ; Write-Host "$total"
Re: Useful Unix commands for data science
#9I recommend "The AWK Programming Language" by Aho, Kernighan, and Weinberger, though it seems to be listed for a hilariously high price on Amazon at the moment. Maybe try to pick up a used copy.
Re: Useful Unix commands for data science
#10I like slicing and dicing with awk, grep and friends too. One thing I find odd that you have to drop to a full language (awk, perl etc) to sum a column of numbers. Am I missing a utility? echo "1\n2\n3\n" | sum # should print 6 with hyphothetical sum command I suppose more generally you could have a 'fold initial op' and: echo "1\n2\n3\n4\n" | fold 0 + # should print 10 echo "1\n2\n3\n4\n" | fold 1 \* # should print…
echo -e "1\n2\n3\n4" | paste -sd+ | bc
kind of cheating though! :-)