Tips on Unix utilities and related topics from @JohnDCook.

Joined August 2011
Filter
Exclude
Time range
-
Near
diff3 compares three files line by line.
1
9
1
19
Unix tool tip retweeted
Mozart's Birthday! q=0.25;e=0.125;for i in G\ $q 0\ $e D\ $e G\ $q 0\ $e D\ $e G\ $e D\ $e G\ $e B\ $e D5\ $e 0\ $q C5\ $q 0\ $e A\ $e C5\ $q 0\ $e A\ $e C5\ $e A\ $e F#\ $e A\ $e D\ $e;do a=($i);n=${a[0]};l=${a[1]};play -n synth saw $n trim 0 $l chorus 0.8 8 21 0.7 4 0.5 -t;done
5
47
9
196
Show this thread
Suppose you have a CSV file with a lot of fields, so many that they wrap around your terminal and are hard to read. Here's how you could see the field names listed vertically. head -n 1 foo.csv | sed "s/,/\n/g"
8
8
98
Now suppose you want to pick out one of the columns with cut. "Is that the 42nd or 43rd column? Let me count again ..." You can number the lines by piping the previous command through nl. head -n 1 foo.csv | sed "s/,/\n/g" | nl
2
17
Now suppose you want to browse the 9th column. cut -d, -f9 | less
1
1
15
But what if you have a tab-separated file rather than a comma-separated file? I don't think you can tell cut to separate on tabs. But you can tell awk to separate on tabs. cat foo.tsv | awk -F'\t' '{print $9}' | less
2
12
Correction: Tab is in fact the default delimiter for cut. But I believe the delimiter can only be one character in cut, but it could be multiple characters in awk.
2
2
13
Error handling in bash scripts jtrocinski.com/posts/Bash-Er…
1
7
33
chmod +x marks a file as executable
3
5
2
36
Using bash to do algebra homework problems
New post: Permutations at the command line johndcook.com/blog/2022/01/2…
3
16
Unix tool tip retweeted
Hey, I know this - it's a UNIX system.
1
27
3
84
Using tr to do logic.
1
9
Unix tool tip retweeted
Play a G major chord "on guitar" using the 'play' command from the sox package. play -n synth pl G2 pl B2 pl D3 pl G3 pl D4 pl G4 delay 0 .05 .1 .15 .2 .25 remix - fade 0 4 .1 norm -1
6
32
6
142
Vim color schemes vimcolors.com/
1
2
17
sdiff shows diff output side-by-side.
4
1
54