-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
1308 lines (1301 loc) · 39.5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>reveal.js</title>
<link rel="stylesheet" href="dist/reset.css">
<link rel="stylesheet" href="dist/reveal.css">
<link rel="stylesheet" href="dist/custom.css">
<link rel="stylesheet" href="dist/theme/black.css" id="theme">
<link rel="stylesheet" href="css/demo.css">
<!-- Theme used for syntax highlighted code -->
<link rel="stylesheet" href="plugin/highlight/monokai.css" id="highlight-theme">
</head>
<body>
<div class="reveal">
<div class="menubar" id="menubar">
<div class="dropdown">
<input id="checkbox_toggle" type="checkbox">
<label for="checkbox_toggle" data-i18n="chooselanguage">Choose language</label>
<div class="langchooser">
<label>
<input type="radio" name="menulangradios" value="en" checked><span>English</span>
</label>
<label>
<input type="radio" name="menulangradios" value="cz"><span>Čeština</span>
</label>
</div>
</div>
</div>
<div class="slides">
<section data-state="intro"> <!-- header and name and repo -->
<section id="intro" data-state="intro">
<h1 data-i18n="title">Shell for quick and dirty<br>"Data Analysis"</h1>
</section>
<section id="intro_2" data-state="intro">
<h3 data-i18n="data_resources">Download following repo</h3>
<a href="https://github.com/trnkatomas/bash_presentation">
https://github.com/trnkatomas/bash_presentation</a>
</section>
<section id="intro_3" data-state="intro">
<h3 data-i18n="prep">Preparation</h3>
<ul>
<li data-i18n="copy_files">
please copy the files from folder<br> EXAMPLE_FILES to /TMP (or any other easily accessible location)
</li>
<li data-i18n="spawn_terminal">
open your terminal and paste all <br>the commands as we will go along
</li>
</ul>
</section>
</section>
<section id="bash_overview_0"> <!-- bash flavours-->
<section id="bash_overview"> <!-- bash flavours-->
<h3>Bash</h3>
<ul>
<li data-i18n="shells">All shells are equal, some of them are just better</li>
<li>Bourne Again SHell</li>
<li><a href="https://fishshell.com/">FiSH</a></li>
<li><a href="https://ohmyz.sh/">ZSH</a></li>
<li><a href="https://mosh.org/">Mosh</a></li>
</ul>
</section>
<section id="bash_overview_1">
<h3 data-i18n="shell_1">Why bother with Bash?</h3>
<ul>
<li data-i18n="shell_2">omnipresent in the world of servers, big data</li>
<li data-i18n="shell_3">fast</li>
<li data-i18n="shell_4">universal</li>
</ul>
</section>
</section>
<section id="quick_ref"> <!-- outline -->
<h3 data-i18n="usefull_command">
Useful commands
</h3>
<div class="left">
<ul>
<li><a href="#/basics">basics</a></li>
<!-- <() >() tee https://serverfault.com/questions/40284/create-virtual-file-from-bash-command-output/40291#40291 -->
<li><a href="#/ls">ls</a></li>
<li><a href="#/file">file</a></li>
<li><a href="#/find">find</a></li>
<li><a href="#/history">history</a></li>
<li><a href="#/cat">cat (tac :)</a></li>
<li><a href="#/head">head/tail</a></li>
<li><a href="#/sort">sort</a></li>
<li><a href="#/cut">cut</a></li>
<li><a href="#/tr-grep-sed">tr & grep & sed</a></li>
</ul>
</div>
<div class="right">
<ul>
<li><a href="#/awk">awk</a></li>
<li><a href="#/paste">paste</a></li>
<li><a href="#/split">split</a></li>
<li><a href="#/join">join</a></li>
<li><a href="#/xargs">xargs</a></li>
<li><a href="#/parallel">parallel</a></li>
<li><a href="#/jq">jq</a></li>
<li><a href="#/bc">bc</a></li>
<li><a href="#/printf">printf</a></li>
<li><a href="#/seq">seq</a></li>
</ul>
</div>
</section>
<section id="basics"> <!-- basics -->
<section id="variables">
<h2 data-i18n="variables">variables</h2>
<ul>
<li><span data-i18n="var_intro">in shell you can obviously have variables</span>
<pre>
<code data-trim data-noescape>
filename=/tmp/28.5.2020.json
</code>
</pre>
</li>
<li><span data-i18n="echo">use <i>echo</i> to display</span>
<pre>
<code data-trim data-noescape>
echo ${filename}
</code>
</pre>
</li>
</section>
<section id="aliases">
<h2 data-i18n="aliases">aliases</h2>
<ul>
<li data-i18n="aliases_2">similar to variables are aliases, for instance to save some typing</li>
<pre>
<code data-trim data-noescape>
alias ll='ls -l'
</code>
</pre>
</section>
<section id="functions">
<h2 data-i18n="functions_1">functions</h2>
<ul>
<li><span data-i18n="functions_2">sometimes a function might come in handy</span>
<pre>
<code data-trim data-noescape>
shift_date() {
date --date "-${1} day" +%Y-%m-%d
}
export -f shift_date
</code>
</pre>
</li>
<li data-i18n="functions_3">this works for bare bash, other shells handle functions differently</li>
</section>
<section id="which">
<h2>which</h2>
<ul>
<li data-i18n="which_1">in order to orient yourself</li>
<li data-i18n="which_2">prints info (full path) for (shell) commands</li>
<pre>
<code data-trim data-noescape>
which head
which ll
which shift_date
which conda
which python
</code>
</pre>
</section>
<section id="man">
<h2>man</h2>
<ul>
<li data-i18n="man">for when the --help parameter simply does not cut it</li>
<pre>
<code data-trim data-noescape>
man sort
</code>
</pre>
</ul>
</section>
<section id="io">
<h2 data-i18n="io_1">redirections</h2>
<ul>
<li><span data-i18n="io_2">in order to save to file</span>
<pre>
<code data-trim data-noescape>
cat /tmp/28.5.2020.json > /tmp/some_other_file.txt
cat /tmp/28.5.2020.json >> /tmp/some_other_file.txt
</code>
</pre>
</li>
<li><span data-i18n="io_3">standard identifiers and tricks are as follows</span>
<pre>
<code data-trim data-noescape data-i18n="io_examples">
1> stdout
2> stderr
&> all of them
2>&1 redirect stderr to stdout
> /dev/null - throw away
command </tmp/28.5.2020.json
</code>
</pre>
</li>
</section>
<section id="magic">
<h2 data-i18n="magic_1">Perl-like magic</h2>
<ul>
<li><span data-i18n="magic_2">eval some code</span>
<pre>
<code data-trim data-noescape>
$()
</code>
</pre>
</li>
<li><span data-i18n="magic_3">last result</span>
<pre>
<code data-trim data-noescape>
$?
</code>
</pre>
</li>
<li><span data-i18n="magic_4">execute last command again</span>
<pre>
<code data-trim data-noescape>
$!!
</code>
</pre>
</li>
</ul>
</section>
<section id="magic_contd">
<h2 data-i18n="magic_contd_1">EOL magic</h2>
<ul>
<li><span data-i18n="magic_contd_2">bigger inputs<br>
eg. can come in handy while mangling small python code into bash</span>
<pre>
<code data-trim data-noescape>
sed 's|http://||' <<EOL
http://url1.com
http://url2.com
http://url3.com
EOL
</code>
</pre>
</li>
</section>
<section id="glob">
<h2>glob</h2>
<ul>
<li data-i18n="glob_2">wildcard replacement</li>
<li data-i18n="glob_3">* - replace whathwer</li>
<li data-i18n="glob_4">? - replace one char</li>
<li data-i18n="glob_5">[ab] - character classes</li>
<li data-i18n="glob_6">[0-9] - ranges</li>
<li data-i18n="glob_7">[!0-9] - complements</li>
</ul>
</section>
<section id="keyboard_commands">
<h2 data-i18n="keyboard_commands_1">Keyboards commands</h2>
<ul>
<li data-i18n="keyboard_commands_2">ALT + . - last parameter from previous command</li>
<li data-i18n="keyboard_commands_3">CTRL + K - delete till the end of line</li>
<li data-i18n="keyboard_commands_4">CTRL + W - delete word under cursor</li>
<li data-i18n="keyboard_commands_5">TAB - try to fill in what it can</li>
</ul>
</section>
</section>
<section id="ls"> <!-- ls -->
<section id="ls_1">
<h2>ls</h2>
<ul>
<li><span data-i18n="ls_1">list the directory as a parameter</span>
<pre>
<code data-trim data-noescape data-i18n="ls_1_1">
ls .(default option)
</code>
</pre>
</li>
<li><span data-i18n="ls_2">caveat</span>
<pre>
<code data-trim data-noescape data-i18n="ls_2_1">
ls /tmp/* -- full path
ls /tmp/ -- relative path
</code>
</pre>
</li>
</ul>
</section>
<section id="ls_2">
<ul>
<li><span data-i18n="ls_3">with all the information</span>
<pre>
<code data-trim data-noescape>
ls -l /tmp
</code>
</pre>
</li>
<li><span data-i18n="ls_4">with hidden files</span>
<pre>
<code data-trim data-noescape>
ls -la ~
</code>
</pre>
</li>
</ul>
</section>
<section id="ls_3">
<h4 data-i18n="ls_5">useful flags</h4>
<ul>
<li><span data-i18n="ls_6">do not sort, useful for folder with lot of entries</span>
<pre>
<code data-trim data-noescape>
ls -U ~
</code>
</pre>
</li>
<li><span data-i18n="ls_7">every file on separate line without any other info</span>
<pre>
<code data-trim data-noescape>
ls -1 ~
</code>
</pre>
</li>
<li><span data-i18n="ls_8">sort by date of creation</span>
<pre>
<code data-trim data-noescape>
ls -t | head
</code>
</pre>
</li>
</ul>
</section>
</section>
<section>
<section id="mkdir">
<h3>mkdir</h3>
<ul>
<li data-i18n="mkdir_2">makes directory</li>
<li><span data-i18n="mkdir_2">usefull command -p</span>
<pre>
<code data-trim data-noescape>
mkdir -p /tmp/make/the/whole/path
</code>
</pre>
</li>
<li><span data-i18n="mkdir_2">usefull command {} - cartesian product</span>
<pre>
<code data-trim data-noescape>
mkdir -p /tmp/{a,b}/{c,d}
</code>
</pre>
</li>
</ul>
</section>
<section id="cp_mv">
<h3 data-i18n="cp_mv_1">cp and mv</h3>
<ul>
<li>copy and move files, folders</li>
<li>usefull param <i>-f</i> (force)</li>
<li><span data-i18n="cp_mv_2">clever interpretation</span></li>
</ul>
<pre>
<code data-trim data-noescape>
mv /tmp/28.5.2020.json /tmp/category.tsv /tmp/a
</code>
</pre>
</section>
</section>
<section id="file"> <!-- file -->
<section id="file_1">
<h2>file</h2>
<ul>
<li><span data-i18n="file_1">show info about the file (in Linux, everything is a file), results may vary for different versions, for different implementations: Linux vs. BSD (MacOS)</span>
<pre>
<code data-trim data-noescape>
file /tmp/28.5.2020.json
file /dev/null
</code>
</pre>
</li>
</ul>
</section>
<section id="file_2">
<h2>wc</h2>
<ul>
<li data-i18n="wc_1">show basic counts of the file</li>
<li data-i18n="wc_2">number of lines, number of chars, ...</li>
</ul>
<pre>
<code data-trim data-noescape>
wc -l /tmp/28.5.2020.json
wc -c /tmp/28.5.2020.json
</code>
</pre>
</section>
</section>
<section id="find"> <!-- find -->
<section id="find_1">
<h2>find</h2>
<ul>
<li data-i18n="find_1">supports globbing</li>
<li data-i18n="find_2">long parameters with just one dash</li>
<li data-i18n="find_3">works just fine even with folders with lots of entries</li>
<pre>
<code data-trim data-noescape>
find ./ -name "some_long_name*.txt"
</code>
</pre>
</li>
</ul>
</section>
<section id="find_2">
<h4 data-i18n="find_4">useful flags</h4>
<ul>
<li><span data-i18n="find_5">just files/dirs</span>
<pre>
<code data-trim data-noescape>
find /tmp -name "*.json" -type f/d
</code>
</pre>
</li>
<li><span data-i18n="find_6">just non zero sized files</span>
<pre>
<code data-trim data-noescape>
find /tmp -name "*.json" -size +0k
</code>
</pre>
</li>
<li><span data-i18n="find_7">limit the depth</span>
<pre>
<code data-trim data-noescape>
find /tmp -name "*.json" -maxdepth 1
</code>
</pre>
</li>
</ul>
</section>
</section>
<section id="cat"> <!-- cat (tac :) -->
<section id="cat_1">
<h2>cat (tac :) 🐈</h2>
<ul>
<li><span data-i18n="cat_1">simply output the whole file to stdout</span>
<pre>
<code data-trim data-noescape>
cat /tmp/28.5.2020.json
</code>
</pre>
</li>
<li><span data-i18n="cat_2">roughly equivalent to</span>
<pre>
<code data-trim data-noescape>
</tmp/28.5.2020.json
</code>
</pre>
</li>
<li><span data-i18n="cat_3">caveat</span><br>
<div class="left">
<pre>
<code data-trim data-noescape>
cat /tmp/28.5.2020.json | sed
</code>
</pre>
</div>
<div class="left">
<pre>
<code data-trim data-noescape>
</tmp/28.5.2020.json sed
</code>
</pre>
</div>
</li>
</ul>
</section>
<section id="tee">
<h2>tee ┬</h2>
<ul>
<li><span data-i18n="tee_1">super useful if you would like to store some intermediate results</span>
<pre>
<code data-trim data-noescape>
</tmp/28.5.2020.json grep "amazon" | tee -a /tmp/amazon | sed ..
</code>
</pre>
</li>
</ul>
</section>
<section id="more_less">
<h2>more / less</h2>
<ul>
<li data-i18n="more_less_1">for viewing the content that is unable to fit the screen</li>
<li><span data-i18n="more_less_2">MORE go simply over the file, LESS is more feature rich</span>
<pre>
<code data-trim data-noescape>
cat /tmp/28.5.2020.json | more
cat /tmp/28.5.2020.json | less
</code>
</pre>
</li>
</ul>
</section>
<section id="hexdump">
<h2>hexdump</h2>
<ul>
<li><span data-i18n="hexdump">in order to verify binary data, or non printable chars</span>
<pre>
<code data-trim data-noescape>
hexdump -C 60 /tmp/28.5.2020.json | less
</code>
</pre>
</li>
</ul>
</section>
</section>
<section id="head"> <!-- head/tail -->
<section id="head_1">
<h2>head/tail</h2>
<ul>
<li data-i18n="head_tail_1">simply takes the beggining or end of the file</li>
<li data-i18n="head_tail_2">by default takes 10 lines</li>
<pre>
<code data-trim data-noescape>
head /tmp/28.5.2020.json
</code>
</pre>
</section>
<section id="head_2">
<ul>
<li><span data-i18n="head_tail_2">if you would like to take different number of lines</span>
<pre>
<code data-trim data-noescape>
head -n 1 /tmp/28.5.2020.json
</code>
</pre>
</li>
<li><span data-i18n="head_tail_3">if you have way too long lines, take charactes/bytes</span>
<pre>
<code data-trim data-noescape>
head -c 50 /tmp/28.5.2020.json
</code>
</pre>
</li>
</ul>
</section>
<section id="head_3">
<ul>
<li><span data-i18n="head_tail_4">tail works as expected</span>
<pre>
<code data-trim data-noescape>
tail -n 1 /tmp/28.5.2020.json
</code>
</pre>
</li>
<li><span data-i18n="head_tail_5">nice feature! take after some lines<br> for instance to skip header</span>
<pre>
<code data-trim data-noescape>
tail -n+2 /tmp/28.5.2020.json
</code>
</pre>
</li>
<li><span data-i18n="head_tail_6">or take a look at a problematic part of file</span>
<pre>
<code data-trim data-noescape>
tail -n+22 /tmp/28.5.2020.json | head -n 5
</code>
</pre>
</li>
</ul>
</section>
</section>
<section id="cut"> <!-- cut -->
<h2>cut</h2>
<ul>
<li><span data-i18n="cut_1">can take 'column'</span>
<pre>
<code data-trim data-noescape>
cut -f1 /tmp/category.tsv
</code>
</pre>
</li>
<li><span data-i18n="cut_2">can specify range, columns</span>
<pre><code data-trim data-noescape>
cut -f1-4 /tmp/category.tsv
cut -f1,2 /tmp/category.tsv
</code>
</pre>
</li>
<li><span data-i18n="cut_3">change the delimiter</span>
<pre>
<code data-trim data-noescape>
cut -f1 -d, /tmp/28.5.2020.json
</code>
</pre>
</li>
</ul>
</section>
<section id="history"> <!-- history -->
<section id="history_1">
<h2>history</h2>
<ul>
<li><span data-i18n="history_1">bash is kind enough to remember the past commands for you</span>
<pre>
<code data-trim data-noescape>
history
</code>
</pre>
</li>
<li data-i18n="history_2">
with CTRL + R/ CTRL + S you can search backward/forward respectively
</li>
</ul>
</section>
<section id="history_2">
<span data-i18n="history_2_1">No history bash</span>
<pre>
<code data-trim data-noescape>
bash --init-file <(echo '. ~/.bashrc; unset HISTFILE')
</code>
</pre>
</section>
</section>
<section id="tr-grep-sed"> <!-- tr & grep & sed -->
<section id="tr_grep_sed_1">
<h3>tr</h3>
<ul>
<li><span data-i18n="tr_1">edit on character level</span>
<pre><code data-trim data-noescape>
tr "," "\t"
</code></pre>
</li>
<li><span data-i18n="tr_2">delete</span>
<pre><code data-trim data-noescape>
tr -d "\r"
</code></pre>
</li>
<li><span data-i18n="tr_3">globbing patterns</span>
<pre><code data-trim data-noescape>
tr '[:upper:]' '[:lower:]'
</code></pre>
</li>
<li><span data-i18n="tr_4">cleaning</span>
<pre><code data-trim data-noescape>
tr -s ' '
</code></pre>
</li>
</ul>
</section>
<section id="tr_grep_sed_2"> <!-- grep -->
<h2>grep</h2>
<ul>
<li><span data-i18n="grep_1">matching interesting lines</span>
<pre><code data-trim data-noescape>
cat /tmp/28.5.2020.json | grep microsoft
</code>
</pre>
</li>
<li><span data-i18n="grep_2">regexp support</span>
<pre><code data-trim data-noescape>
cat /tmp/28.5.2020.json | grep -e 'cnt":[0-9]}'
</code>
</pre>
</li>
</ul>
</section>
<section id="tr_grep_sed_3"> <!-- grep II -->
<h2>grep II</h2>
<ul>
<li><span data-i18n="grep_4">with line numbers</span>
<pre><code data-trim data-noescape>
cat /tmp/28.5.2020.json | grep -n microsoft
</code>
</pre>
</li>
<li><span data-i18n="grep_5">inverse selection</span>
<pre><code data-trim data-noescape>
cat /tmp/28.5.2020.json | grep -v microsoft
</code>
</pre>
</li>
<li><span data-i18n="grep_6">output just the matched part</span>
<pre><code data-trim data-noescape>
cat /tmp/28.5.2020.json | grep -o -e 'cnt":[0-9]}'
</code>
</pre>
</li>
</ul>
</section>
<section id="tr_grep_sed_4">
<h2>sed</h2>
<ul>
<li><span data-i18n="sed_1">even more powerful stream editing tool</span>
<pre>
<code data-trim data-noescape>
cat /tmp/28.5.2020.json | sed 's#cnt#count#gm'
</code>
</pre>
</li>
<li><span data-i18n="sed_2">inplace editing, dangerous zone</span>
<pre>
<code data-trim data-noescape>
sed -i 's#cnt#count#gm' /tmp/28.5.2020.json
</code>
</pre>
</li>
</ul>
</section>
<section id="tr_grep_sed_5">
<h2>sed II</h2>
<ul>
<li><span data-i18n="sed_3">hairy regexes = true power</span>
<pre>
<code data-trim data-noescape>
sed 's#[^ ]##gm'
</code>
</pre>
</li>
<li><span data-i18n="sed_4">more complicated example, several attempts were needed</span>
<pre>
<code data-trim data-noescape>
cat /tmp/28.5.2020.json | \
sed 's#\([0-9]\{4\}\)-\([0-9]\{2\}\)-\([0-9]\{2\}\)#\3/\2/\1#gm'
</code>
</pre>
</li>
</ul>
</section>
<section id="tr_grep_sed_6">
<h2>sed III</h2>
<ul>
<li><span data-i18n="sed_5">matching cross the endline</span>
<pre>
<code data-trim data-noescape>
cat /tmp/28.5.2020.json | \
sed -z 's#\n#\t#gm'
</code>
</pre>
</li>
<li><span data-i18n="sed_6">command chaining</span>
<pre>
<code data-trim data-noescape>
cat /tmp/28.5.2020.json | \
sed -z 's#\n#\t#gm;s#\s\+# #gm'
</code>
</pre>
</li>
</ul>
</section>
</section>
<section id="sort"> <!-- sort -->
<section id="sort_1">
<h2>sort</h2>
<ul>
<li><span data-i18n="sort_1">sort inputs</span>
<pre>
<code data-trim data-noescape>
sort /tmp/28.5.2020.json
</code>
</pre>
</li>
<li data-i18n="sort_2">
supports parallel execution in newer versions
</li>
</ul>
</section>
<section id="sort_2">
<h2 data-i18n="sort_4">useful examples</h2>
<ul>
<li><pre><code data-trim data-noescape>
cat /tmp/28.5.2020.json | cut -f1,2 -d, | sort -k1b,1
</code></pre>
</li>
<li>
<pre><code data-trim data-noescape>
cat /tmp/28.5.2020.json | awk -F'[:,}]' '{print $2"\t"$8}' | \
sort -n -k2,2
</code>
</pre>
</li>
<li>
<pre><code data-trim data-noescape>
cat /tmp/28.5.2020.json | awk -F'[:,}]' '{print $2"\t"$8}' | \
sort -r -k1,1
</code>
</pre>
</li>
<li><pre>
<code data-trim data-noescape>
cat /tmp/28.5.2020.json | sort -S60G
</code>
</pre>
</li>
</ul>
</section>
<section id="sort_3">
<h2 data-i18n="sort_5">flags vs programs</h2>
<ul>
<li data-i18n="sort_6">uniq entries</li>
<pre>
<code data-trim data-noescape>
cat /tmp/28.5.2020.json | cut -f1 -d, | sort -u
cat /tmp/28.5.2020.json | cut -f1 -d, | sort | uniq -c
</code>
</pre>
<li data-i18n="sort_7">random groups together/all </li>
<pre>
<code data-trim data-noescape>
cat /tmp/28.5.2020.json | cut -f1 -d, | sort -uR
cat /tmp/28.5.2020.json | cut -f1 -d, | shuf
</code>
</pre>
</ul>
</section>
</section>
<section id="awk"> <!-- awk -->
<section id="awk_1">
<h2>awk</h2>
<ul>
<li><span data-i18n="awk_1">most basic usage, select columns, whitespace delimited</span>
<pre>
<code data-trim data-noescape>
awk '{print $1}'
</code>
</pre>
</li>
<li><span data-i18n="awk_2">useful special variables</span>
<pre>
<code data-trim data-noescape>
echo -e "a b\nc d" |\
awk '{print NR,NF}'
</code>
</pre>
</li>
</ul>
</section>
<section id="awk_2">
<h2>awk II</h2>
<ul>
<li><span data-i18n="awk_3">specify delimiters</span>
<pre>
<code data-trim data-noescape>
cat /tmp/28.5.2020.json | awk -F '[,:]' '{print $2,$8}'
</code>
</pre>
</li>
<li><span data-i18n="awk_4">conditions</span>
<pre>
<code data-trim data-noescape>
cat /tmp/category.tsv | \
awk '{if ($2 == "amazon"){print $0}}'
</code>
</pre>
</li>
</ul>
</section>
<section id="awk_3">
<h2>awk III</h2>
<ul>
<li><span data-i18n="awk_5">env variables</span>
<pre>
<code data-trim data-noescape>
var=5; cat /tmp/28.5.2020.json | \
awk -v val=$var '{print val"\t"$1}'
</code>
</pre>
</li>
<li><span data-i18n="awk_6">sub in input</span>
<pre>
<code data-trim data-noescape>
cat /tmp/category.tsv | \
awk -F '[\t]' '{gsub("[[:space:]]","_", $2);print $2}'
</code>
</pre>
</li>
</ul>
</section>
<section id="awk_4">
<h2>awk IV</h2>
<ul>
<li><span data-i18n="awk_7">operations (arrays)</span>
<pre>
<code data-trim data-noescape>
cat /tmp/category.tsv | \
awk \
'BEGIN {
FS="[^a-zA-Z]+"
}
{
for (i=1; i<=NF; i++)
words[tolower($i)]++
}
END {
for (i in words)
print i, words[i]
}'
</code>
</pre>
</li>
</ul>
</section>
</section>
<section id=xargs> <!-- xargs -->
<h2>xargs</h2>
<ul>
<li><span data-i18n="xargs_1"> build and run command from stdin</span>
<pre><code data-trim data-noescape>
ls -1 /tmp | xargs wc -l
</code>
</pre>
</li>
<li><span data-i18n="xargs_2">you can do some more complicated stuff</span>
<pre><code data-trim data-noescape>
kubectl -n tlab-dod-prod get jobs | \
grep "angler-whiteset-feeder" | \
awk '{print $1}' | \
xargs -I {} kubectl delete job {}
</code>
</pre>
</li>
<li><span data-i18n="xargs_3">enable multiprocessing</span>
<pre><code data-trim data-noescape>
echo 8.4/2 | xargs -P 8 wc -l
</code>
</pre>
</li>
</ul>
</section>
<section id="paste"> <!-- paste -->
<h2>paste</h2>
<ul>
<li><span data-i18n="paste_1">merge the lines of input files</span>
<pre>
<code data-trim data-noescape>
paste \
<(seq 1 $(wc -l /tmp/28.5.2020.json|awk '{print $1}')) \
/tmp/28.5.2020.json
</code>
</pre>
</li>
<li><span data-i18n="paste_2">merge the lines of file together</span>
<pre>
<code data-trim data-noescape>
factorial (){
seq 1 $1 | paste -s -d'*' | bc
}
</code>
</pre>
</li>
</ul>
</section>
<section id="split"> <!-- split -->
<h2>split</h2>
<ul>
<li><span data-i18n="split_1">split into chunks</span>
<pre>
<code data-trim data-noescape>
split -n 2 /tmp/28.5.2020.json
</code>
</pre>
</li>
<li><span data-i18n="split_2">split by number of lines</span>
<pre>
<code data-trim data-noescape>
split -l 2 /tmp/28.5.2020.json
</code>
</pre>
</li>
<li><span data-i18n="split_3">named prefix</span>
<pre>
<code data-trim data-noescape>
split -l 2 /tmp/28.5.2020.json target_batches
</code>
</pre>
</li>
</ul>
</section>
<section id="join"> <!-- join -->
<h2>join</h2>
<ul>
<li><span data-i18n="join_1">Join two sorted files together</span>
<pre><code data-trim data-noescape>
join -11 -22 \
<(cat /tmp/28.5.2020.json | \
jq -r ".[]|[.target, .cnt]|@tsv" | sort -k1) \
<(cat /tmp/category.tsv | sort -k2b,2)
</code>
</pre>
</li>
<li><span data-i18n="join_2">put missing entries into output</span>
<pre><code data-trim data-noescape>
join -j1 -a2
</code>
</pre>
</li>
<li><span data-i18n="join_3">override default delimiter</span>
<pre><code data-trim data-noescape>
join -j1 -t ' '
</code>