-
Notifications
You must be signed in to change notification settings - Fork 27
/
example.nu
2399 lines (1378 loc) · 50.8 KB
/
example.nu
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
alias ll = ls -l
[[status]; [UP] [UP]] | all {|el| $el.status == UP }
[foo bar 2 baz] | all {|| ($in | describe) == 'string' }
[0 2 4 6] | enumerate | all {|i| $i.item == $i.index * 2 }
let cond = {|el| ($el mod 2) == 0 }; [2 4 6 8] | all $cond
ansi green
ansi reset
$'(ansi red_bold)Hello(ansi reset) (ansi green_dimmed)Nu(ansi reset) (ansi purple_italic)World(ansi reset)'
$'(ansi rb)Hello(ansi reset) (ansi gd)Nu(ansi reset) (ansi pi)World(ansi reset)'
$"(ansi -e '3;93;41m')Hello(ansi reset)" # italic bright yellow on red background
let bold_blue_on_red = { # `fg`, `bg`, `attr` are the acceptable keys, all other keys are considered invalid and will throw errors.
fg: '#0000ff'
bg: '#ff0000'
attr: b
}
$"(ansi -e $bold_blue_on_red)Hello Nu World(ansi reset)"
'Hello, Nushell! This is a gradient.' | ansi gradient --fgstart '0x40c9ff' --fgend '0xe81cff'
'Hello, Nushell! This is a gradient.' | ansi gradient --fgstart '0x40c9ff' --fgend '0xe81cff' --bgstart '0xe81cff' --bgend '0x40c9ff'
'Hello, Nushell! This is a gradient.' | ansi gradient --fgstart '0x40c9ff'
'Hello, Nushell! This is a gradient.' | ansi gradient --fgend '0xe81cff'
'file:///file.txt' | ansi link --text 'Open Me!'
'https://www.nushell.sh/' | ansi link
[[url text]; [https://example.com Text]] | ansi link url
$'(ansi green)(ansi cursor_on)hello' | ansi strip
[[status]; [UP] [DOWN] [UP]] | any {|el| $el.status == DOWN }
[1 2 3 4] | any {|| ($in | describe) == 'string' }
[9 8 7 6] | enumerate | any {|i| $i.item == $i.index * 2 }
let cond = {|e| $e mod 2 == 1 }; [2 4 1 6 8] | any $cond
[0,1,2,3] | append 4
[0,1] | append [2,3,4]
[0,1] | append [2,nu,4,shell]
ast 'hello'
ast 'ls | where name =~ README'
ast 'for x in 1..10 { echo $x '
2 | bits and 2
[4 3 2] | bits and 2
[4 3 2] | bits not
[4 3 2] | bits not -n '2'
[4 3 2] | bits not -s
2 | bits or 6
[8 3 2] | bits or 2
17 | bits rol 2
[5 3 2] | bits rol 2
17 | bits ror 60
[15 33 92] | bits ror 2 -n '1'
2 | bits shl 7
2 | bits shl 7 -n '1'
0x7F | bits shl 1 -s
[5 3 2] | bits shl 2
8 | bits shr 2
[15 35 2] | bits shr 2
2 | bits xor 2
[8 3 2] | bits xor 2
loop { break }
0x[1F FF AA AA] | bytes add 0x[AA]
0x[1F FF AA AA] | bytes add 0x[AA BB] -i 1
0x[FF AA AA] | bytes add 0x[11] -e
0x[FF AA BB] | bytes add 0x[11 22 33] -e -i 1
0x[33 44 55 10 01 13] | bytes at 3..<4
0x[33 44 55 10 01 13] | bytes at 3..6
0x[33 44 55 10 01 13] | bytes at 3..
0x[33 44 55 10 01 13] | bytes at ..<4
[[ColA ColB ColC]; [0x[11 12 13] 0x[14 15 16] 0x[17 18 19]]] | bytes at 1.. ColB ColC
bytes build 0x[01 02] 0x[03] 0x[04]
[0x[11] 0x[13 15]] | bytes collect
[0x[11] 0x[33] 0x[44]] | bytes collect 0x[01]
0x[1F FF AA AA] | bytes ends-with 0x[AA]
0x[1F FF AA AA] | bytes ends-with 0x[FF AA AA]
0x[1F FF AA AA] | bytes ends-with 0x[11]
0x[33 44 55 10 01 13 44 55] | bytes index-of 0x[44 55]
0x[33 44 55 10 01 13 44 55] | bytes index-of -e 0x[44 55]
0x[33 44 55 10 01 33 44 33 44] | bytes index-of -a 0x[33 44]
0x[33 44 55 10 01 33 44 33 44] | bytes index-of -a -e 0x[33 44]
[[ColA ColB ColC]; [0x[11 12 13] 0x[14 15 16] 0x[17 18 19]]] | bytes index-of 0x[11] ColA ColC
0x[1F FF AA AB] | bytes length
[0x[1F FF AA AB] 0x[1F]] | bytes length
0x[10 AA FF AA FF] | bytes remove 0x[10 AA]
0x[10 AA 10 BB 10] | bytes remove -a 0x[10]
0x[10 AA 10 BB CC AA 10] | bytes remove -e 0x[10]
[[ColA ColB ColC]; [0x[11 12 13] 0x[14 15 16] 0x[17 18 19]]] | bytes remove 0x[11] ColA ColC
0x[10 AA FF AA FF] | bytes replace 0x[10 AA] 0x[FF]
0x[10 AA 10 BB 10] | bytes replace -a 0x[10] 0x[A0]
[[ColA ColB ColC]; [0x[11 12 13] 0x[14 15 16] 0x[17 18 19]]] | bytes replace -a 0x[11] 0x[13] ColA ColC
0x[1F FF AA AA] | bytes reverse
0x[FF AA AA] | bytes reverse
0x[1F FF AA AA] | bytes starts-with 0x[1F FF AA]
0x[1F FF AA AA] | bytes starts-with 0x[1F]
0x[1F FF AA AA] | bytes starts-with 0x[11]
cal
cal --full-year 2012
cal --week-start monday
cd ~
cd d/s/9
cd -
char newline
char --list
(char prompt) + (char newline) + (char hamburger)
char -u 1f378
char -i (0x60 + 1) (0x60 + 2)
char -u 1F468 200D 1F466 200D 1F466
clear
[1 2 3] | collect { |x| $x.1 }
{ acronym:PWD, meaning:'Print Working Directory' } | columns
[[name,age,grade]; [bill,20,a]] | columns
[[name,age,grade]; [bill,20,a]] | columns | first
[[name,age,grade]; [bill,20,a]] | columns | select 1
[["Hello" "World"]; [null 3]] | compact Hello
[["Hello" "World"]; [null 3]] | compact World
[1, null, 2] | compact
^external arg1 | complete
do { ^external arg1 } | complete
config env
config nu
config reset
const x = 10
const x = { a: 10, b: 20 }
for i in 1..10 { if $i == 5 { continue }; print $i }
cp myfile dir_b
cp -r dir_a dir_b
cp -r -v dir_a dir_b
cp *.txt dir_a
"2021-10-22 20:00:12 +01:00" | date format
date now | date format "%Y-%m-%d %H:%M:%S"
date now | date format "%Y-%m-%d %H:%M:%S"
"2021-10-22 20:00:12 +01:00" | date format "%Y-%m-%d"
"2021-10-22 20:00:12 +01:00" | date humanize
date list-timezone | where timezone =~ Shanghai
date now | date format "%Y-%m-%d %H:%M:%S"
(date now) - 2019-05-01
(date now) - 2019-05-01T04:12:05.20+08:00
date now | debug
date to-record
date now | date to-record
'2020-04-12T22:10:57.123+02:00' | date to-record
date to-table
date now | date to-table
2020-04-12T22:10:57.000000789+02:00 | date to-table
date now | date to-timezone '+0500'
date now | date to-timezone local
date now | date to-timezone US/Hawaii
"2020-10-10 10:00:00 +02:00" | date to-timezone "+0500"
'hello' | debug
['hello'] | debug
[[version patch]; ['0.1.0' false] ['0.1.1' true] ['0.2.0' false]] | debug
^cat myfile.q | decode utf-8
0x[00 53 00 6F 00 6D 00 65 00 20 00 44 00 61 00 74 00 61] | decode utf-16be
'U29tZSBEYXRh' | decode base64
'U29tZSBEYXRh' | decode base64 --binary
'0102030A0a0B' | decode hex
'01 02 03 0A 0a 0B' | decode hex
def say-hi [] { echo 'hi' }; say-hi
def say-sth [sth: string] { echo $sth }; say-sth hi
def-env foo [] { let-env BAR = "BAZ" }; foo; $env.BAR
ls -la | default 'nothing' target
$env | get -i MY_ENV | default 'abc'
[1, 2, null, 4] | default 3
'hello' | describe
'a b c' | detect columns -n
$'c1 c2 c3(char nl)a b c' | detect columns
[[a b]; [1 2] [1 4] [2 6] [2 4]]
| dfr into-df
| dfr group-by a
| dfr agg [
(dfr col b | dfr min | dfr as "b_min")
(dfr col b | dfr max | dfr as "b_max")
(dfr col b | dfr sum | dfr as "b_sum")
]
[[a b]; [1 2] [1 4] [2 6] [2 4]]
| dfr into-lazy
| dfr group-by a
| dfr agg [
(dfr col b | dfr min | dfr as "b_min")
(dfr col b | dfr max | dfr as "b_max")
(dfr col b | dfr sum | dfr as "b_sum")
]
| dfr collect
[false false false] | dfr into-df | dfr all-false
let s = ([5 6 2 10] | dfr into-df);
let res = ($s > 9);
$res | dfr all-false
[true true true] | dfr into-df | dfr all-true
let s = ([5 6 2 8] | dfr into-df);
let res = ($s > 9);
$res | dfr all-true
let a = ([[a b]; [1 2] [3 4]] | dfr into-df);
$a | dfr append $a
let a = ([[a b]; [1 2] [3 4]] | dfr into-df);
$a | dfr append $a --col
[1 3 2] | dfr into-df | dfr arg-max
[1 3 2] | dfr into-df | dfr arg-min
[1 2 2 3 3] | dfr into-df | dfr arg-sort
[1 2 2 3 3] | dfr into-df | dfr arg-sort -r
[false true false] | dfr into-df | dfr arg-true
[1 2 2 3 3] | dfr into-df | dfr arg-unique
let df = ([[a b]; [one 1] [two 2] [three 3]] | dfr into-df);
$df | dfr select (dfr arg-where ((dfr col b) >= 2) | dfr as b_arg)
dfr col a | dfr as new_a | dfr into-nu
["2021-12-30" "2021-12-31"] | dfr into-df | dfr as-datetime "%Y-%m-%d"
["2021-12-30 00:00:00" "2021-12-31 00:00:00"] | dfr into-df | dfr as-datetime "%Y-%m-%d %H:%M:%S"
[[a b]; [6 2] [4 2] [2 2]] | dfr into-df | dfr reverse | dfr cache
dfr col a | dfr into-nu
[[a b]; [1 2] [3 4]] | dfr into-lazy | dfr collect
[[a b]; [1 2] [3 4]] | dfr into-df | dfr columns
let df = ([[a b c]; [one two 1] [three four 2]] | dfr into-df);
$df | dfr with-column ((dfr concat-str "-" [(dfr col a) (dfr col b) ((dfr col c) * 2)]) | dfr as concat)
let other = ([za xs cd] | dfr into-df);
[abc abc abc] | dfr into-df | dfr concatenate $other
[abc acb acb] | dfr into-df | dfr contains ab
let s = ([1 1 0 0 3 3 4] | dfr into-df);
($s / $s) | dfr count-null
[1 2 3 4 5] | dfr into-df | dfr cumulative sum
[[a b]; [1 2] [3 4]] | dfr into-df | dfr drop a
[[a b]; [1 2] [3 4] [1 2]] | dfr into-df | dfr drop-duplicates
let df = ([[a b]; [1 2] [3 0] [1 2]] | dfr into-df);
let res = ($df.b / $df.b);
let a = ($df | dfr with-column $res --name res);
$a | dfr drop-nulls
let s = ([1 2 0 0 3 4] | dfr into-df);
($s / $s) | dfr drop-nulls
[[a b]; [1 2] [3 4]] | dfr into-df | dfr dtypes
[[a b]; [1 2] [3 4]] | dfr into-df | dfr dummies
[1 2 2 3 3] | dfr into-df | dfr dummies
(dfr col a) > 2) | dfr expr-not
[[a b]; [6 2] [4 2] [2 2]] | dfr into-df | dfr fetch 2
[1 2 NaN 3 NaN] | dfr into-df | dfr fill-nan 0
[[a b]; [0.2 1] [0.1 NaN]] | dfr into-df | dfr fill-nan 0
[1 2 2 3 3] | dfr into-df | dfr shift 2 | dfr fill-null 0
[[a b]; [6 2] [4 2] [2 2]] | dfr into-df | dfr filter ((dfr col a) >= 4)
let mask = ([true false] | dfr into-df);
[[a b]; [1 2] [3 4]] | dfr into-df | dfr filter-with $mask
[[a b]; [1 2] [3 4]] | dfr into-df | dfr filter-with ((dfr col a) > 1)
dfr col a | dfr first
[[a b]; [1 2] [3 4]] | dfr into-df | dfr first
[[a b]; [1 2] [3 4]] | dfr into-df | dfr first 2
[[a b]; [1 2] [3 4]] | dfr into-df | dfr get a
let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
let df = ([$dt $dt] | dfr into-df);
$df | dfr get-day
let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
let df = ([$dt $dt] | dfr into-df);
$df | dfr get-hour
let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
let df = ([$dt $dt] | dfr into-df);
$df | dfr get-minute
let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
let df = ([$dt $dt] | dfr into-df);
$df | dfr get-month
let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
let df = ([$dt $dt] | dfr into-df);
$df | dfr get-nanosecond
let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
let df = ([$dt $dt] | dfr into-df);
$df | dfr get-ordinal
let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
let df = ([$dt $dt] | dfr into-df);
$df | dfr get-second
let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
let df = ([$dt $dt] | dfr into-df);
$df | dfr get-week
let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
let df = ([$dt $dt] | dfr into-df);
$df | dfr get-weekday
let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
let df = ([$dt $dt] | dfr into-df);
$df | dfr get-year
[[a b]; [1 2] [1 4] [2 6] [2 4]]
| dfr into-df
| dfr group-by a
| dfr agg [
(dfr col b | dfr min | dfr as "b_min")
(dfr col b | dfr max | dfr as "b_max")
(dfr col b | dfr sum | dfr as "b_sum")
]
[[a b]; [1 2] [1 4] [2 6] [2 4]]
| dfr into-lazy
| dfr group-by a
| dfr agg [
(dfr col b | dfr min | dfr as "b_min")
(dfr col b | dfr max | dfr as "b_max")
(dfr col b | dfr sum | dfr as "b_sum")
]
| dfr collect
[[a b];[1 2] [3 4]] | dfr into-df
[[1 2 a] [3 4 b] [5 6 c]] | dfr into-df
[a b c] | dfr into-df
[true true false] | dfr into-df
[[a b];[1 2] [3 4]] | dfr into-lazy
dfr col a | dfr into-nu
[[a b]; [1 2] [3 4]] | dfr into-df | dfr into-nu
[[a b]; [1 2] [5 6] [3 4]] | dfr into-df | dfr into-nu -t -n 1
[5 6 6 6 8 8 8] | dfr into-df | dfr is-duplicated
[[a, b]; [1 2] [1 2] [3 3] [3 3] [1 1]] | dfr into-df | dfr is-duplicated
let other = ([1 3 6] | dfr into-df);
[5 6 6 6 8 8 8] | dfr into-df | dfr is-in $other
let df = ([[a b]; [one 1] [two 2] [three 3]] | dfr into-df);
$df | dfr with-column (dfr col a | dfr is-in [one two] | dfr as a_in)
dfr col a | dfr is-not-null
let s = ([5 6 0 8] | dfr into-df);
let res = ($s / $s);
$res | dfr is-not-null
dfr col a | dfr is-null
let s = ([5 6 0 8] | dfr into-df);
let res = ($s / $s);
$res | dfr is-null
[5 6 6 6 8 8 8] | dfr into-df | dfr is-unique
[[a, b]; [1 2] [1 2] [3 3] [3 3] [1 1]] | dfr into-df | dfr is-unique
let df_a = ([[a b c];[1 "a" 0] [2 "b" 1] [1 "c" 2] [1 "c" 3]] | dfr into-lazy);
let df_b = ([["foo" "bar" "ham"];[1 "a" "let"] [2 "c" "var"] [3 "c" "const"]] | dfr into-lazy);
$df_a | dfr join $df_b a foo | dfr collect
let df_a = ([[a b c];[1 "a" 0] [2 "b" 1] [1 "c" 2] [1 "c" 3]] | dfr into-df);
let df_b = ([["foo" "bar" "ham"];[1 "a" "let"] [2 "c" "var"] [3 "c" "const"]] | dfr into-lazy);
$df_a | dfr join $df_b a foo
dfr col a | dfr last
[[a b]; [1 2] [3 4]] | dfr into-df | dfr last 1
dfr lit 2 | dfr into-nu
[Abc aBc abC] | dfr into-df | dfr lowercase
let test = ([[a b];[1 2] [3 4]] | dfr into-df);
ls
[[a b]; [6 2] [1 4] [4 1]] | dfr into-df | dfr max
[[a b]; [one 2] [one 4] [two 1]]
| dfr into-df
| dfr group-by a
| dfr agg (dfr col b | dfr max)
[[a b]; [one 2] [one 4] [two 1]]
| dfr into-df
| dfr group-by a
| dfr agg (dfr col b | dfr mean)
[[a b]; [6 2] [4 2] [2 2]] | dfr into-df | dfr mean
[[a b]; [6 2] [4 2] [2 2]] | dfr into-df | dfr median
[[a b]; [one 2] [one 4] [two 1]]
| dfr into-df
| dfr group-by a
| dfr agg (dfr col b | dfr median)
[[a b c d]; [x 1 4 a] [y 2 5 b] [z 3 6 c]] | dfr into-df | dfr melt -c [b c] -v [a d]
[[a b]; [one 2] [one 4] [two 1]]
| dfr into-df
| dfr group-by a
| dfr agg (dfr col b | dfr min)
[[a b]; [6 2] [1 4] [4 1]] | dfr into-df | dfr min
dfr col a | dfr n-unique
[1 1 2 2 3 3 4] | dfr into-df | dfr n-unique
[true false true] | dfr into-df | dfr not
dfr open test.csv
dfr when ((dfr col a) > 2) 4 | dfr otherwise 5
dfr when ((dfr col a) > 2) 4 | dfr when ((dfr col a) < 0) 6 | dfr otherwise 0
[[a b]; [6 2] [1 4] [4 1]]
| dfr into-lazy
| dfr with-column (
dfr when ((dfr col a) > 2) 4 | dfr otherwise 5 | dfr as c
)
| dfr with-column (
dfr when ((dfr col a) > 5) 10 | dfr when ((dfr col a) < 2) 6 | dfr otherwise 0 | dfr as d
)
| dfr collect
[[a b]; [one 2] [one 4] [two 1]]
| dfr into-df
| dfr group-by a
| dfr agg (dfr col b | dfr quantile 0.5)
[[a b]; [6 2] [1 4] [4 1]] | dfr into-df | dfr quantile 0.5
[[a b]; [1 2] [3 4]] | dfr into-df | dfr query 'select a from df'
[5 6 7 8] | dfr into-df | dfr rename '0' new_name
[[a b]; [1 2] [3 4]] | dfr into-df | dfr rename a a_new
[[a b]; [1 2] [3 4]] | dfr into-df | dfr rename [a b] [a_new b_new]
[abc abc abc] | dfr into-df | dfr replace -p ab -r AB
[abac abac abac] | dfr into-df | dfr replace-all -p a -r A
[[a b]; [6 2] [4 2] [2 2]] | dfr into-df | dfr reverse
[1 2 3 4 5] | dfr into-df | dfr rolling sum 2 | dfr drop-nulls
[1 2 3 4 5] | dfr into-df | dfr rolling max 2 | dfr drop-nulls
[[a b]; [1 2] [3 4]] | dfr into-df | dfr sample -n 1
[[a b]; [1 2] [3 4] [5 6]] | dfr into-df | dfr sample -f 0.5 -e
[[a b]; [6 2] [4 2] [2 2]] | dfr into-df | dfr select a
let s = ([1 2 2 3 3] | dfr into-df | dfr shift 2);
let mask = ($s | dfr is-null);
$s | dfr set 0 --mask $mask
let series = ([4 1 5 2 4 3] | dfr into-df);
let indices = ([0 2] | dfr into-df);
$series | dfr set-with-idx 6 -i $indices
[[a b]; [1 2] [3 4]] | dfr into-df | dfr shape
[1 2 2 3 3] | dfr into-df | dfr shift 2 | dfr drop-nulls
[[a b]; [1 2] [3 4]] | dfr into-df | dfr slice 0 1
[[a b]; [6 2] [1 4] [4 1]] | dfr into-df | dfr sort-by a
[[a b]; [6 2] [1 1] [1 4] [2 4]] | dfr into-df | dfr sort-by [a b] -r [false true]
[[a b]; [one 2] [one 2] [two 1] [two 1]]
| dfr into-df
| dfr group-by a
| dfr agg (dfr col b | dfr std)
[[a b]; [6 2] [4 2] [2 2]] | dfr into-df | dfr std
[a ab abc] | dfr into-df | dfr str-lengths
[abcded abc321 abc123] | dfr into-df | dfr str-slice 1 -l 2
let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
let df = ([$dt $dt] | dfr into-df);
$df | dfr strftime "%Y/%m/%d"
[[a b]; [one 2] [one 4] [two 1]]
| dfr into-df
| dfr group-by a
| dfr agg (dfr col b | dfr sum)
[[a b]; [6 2] [1 4] [4 1]] | dfr into-df | dfr sum
[[a b]; [1 1] [1 1]] | dfr into-df | dfr summary
let df = ([[a b]; [4 1] [5 2] [4 3]] | dfr into-df);
let indices = ([0 2] | dfr into-df);
$df | dfr take $indices
let series = ([4 1 5 2 4 3] | dfr into-df);
let indices = ([0 2] | dfr into-df);
$series | dfr take $indices
[[a b]; [1 2] [3 4]] | dfr into-df | dfr to-arrow test.arrow
[[a b]; [1 2] [3 4]] | dfr into-df | dfr to-csv test.csv
[[a b]; [1 2] [3 4]] | dfr into-df | dfr to-csv test.csv -d '|'
[[a b]; [1 2] [3 4]] | dfr into-df | dfr to-parquet test.parquet
[2 2 2 2 2] | dfr into-df | dfr unique
col a | unique
[Abc aBc abC] | dfr into-df | dfr uppercase
[5 5 5 5 6 6] | dfr into-df | dfr value-counts
[[a b]; [6 2] [4 2] [2 2]] | dfr into-df | dfr var
[[a b]; [one 2] [one 2] [two 1] [two 1]]
| dfr into-df
| dfr group-by a
| dfr agg (dfr col b | dfr var)
dfr when ((dfr col a) > 2) 4
dfr when ((dfr col a) > 2) 4 | dfr when ((dfr col a) < 0) 6
[[a b]; [6 2] [1 4] [4 1]]
| dfr into-lazy
| dfr with-column (
dfr when ((dfr col a) > 2) 4 | dfr otherwise 5 | dfr as c
)
| dfr with-column (
dfr when ((dfr col a) > 5) 10 | dfr when ((dfr col a) < 2) 6 | dfr otherwise 0 | dfr as d
)
| dfr collect
[[a b]; [1 2] [3 4]]
| dfr into-df
| dfr with-column ([5 6] | dfr into-df) --name c
[[a b]; [1 2] [3 4]]
| dfr into-lazy
| dfr with-column [
((dfr col a) * 2 | dfr as "c")
((dfr col a) * 3 | dfr as "d")
]
| dfr collect
do { echo hello }
let text = "I am enclosed"; let hello = {|| echo $text}; do $hello
do -i { thisisnotarealcommand }
do -s { thisisnotarealcommand }
do -p { nu -c 'exit 1' }; echo "I'll still run"
do -c { nu -c 'exit 1' } | myscarycommand
do {|x| 100 + $x } 77
77 | do {|x| 100 + $in }
[0,1,2,3] | drop
[0,1,2,3] | drop 0
[0,1,2,3] | drop 2
[[a, b]; [1, 2] [3, 4]] | drop 1
[[lib, extension]; [nu-lib, rs] [nu-core, rb]] | drop column
[sam,sarah,2,3,4,5] | drop nth 0 1 2
[0,1,2,3,4,5] | drop nth 0 1 2
[0,1,2,3,4,5] | drop nth 0 2 4
[0,1,2,3,4,5] | drop nth 2 0 4
[first second third fourth fifth] | drop nth (1..3)
[0,1,2,3,4,5] | drop nth 1..
[0,1,2,3,4,5] | drop nth 3..
du
[1 2 3] | each {|e| 2 * $e }
{major:2, minor:1, patch:4} | values | each {|| into string }
[1 2 3 2] | each {|e| if $e == 2 { "two" } }
[1 2 3] | enumerate | each {|e| if $e.item == 2 { $"found 2 at ($e.index)!"} }
[1 2 3] | each --keep-empty {|e| if $e == 2 { "found 2!"} }
[1 2 3 2 1] | each while {|e| if $e < 3 { $e * 2 } }
[1 2 stop 3 4] | each while {|e| if $e != 'stop' { $"Output: ($e)" } }
[1 2 3] | enumerate | each while {|e| if $e.item < 2 { $"value ($e.item) at ($e.index)!"} }
echo 1 2 3
echo $in
"負けると知って戦うのが、遥かに美しいのだ" | encode shift-jis
"🎈" | encode -i shift-jis
0x[09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0] | encode base64
'Some Data' | encode base64
'Some Data' | encode base64 --character-set binhex
0x[09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0] | encode hex
enter ../dir-foo
[a, b, c] | enumerate
error make {msg: "my custom error message"}
error make {
msg: "my custom error message"
label: {
text: "my custom label text" # not mandatory unless $.label exists
start: 123 # not mandatory unless $.label.end is set
end: 456 # not mandatory unless $.label.start is set
}
}
def foo [x] {
let span = (metadata $x).span;
error make {
msg: "this is fishy"
label: {
text: "fish right here"
start: $span.start
end: $span.end
}
}
}
[1 2 3 4 5] | every 2
[1 2 3 4 5] | every 2 --skip
exec ps aux
exec nautilus
exit
exit --now
explain {|| ls | sort-by name type -i | get name } | table -e
sys | explore
ls | explore --head false
glob *.md | each {|| open } | explore -i
open file.json | explore -p | to json | save part.json
module utils { export def my-command [] { "hello" } }; use utils my-command; my-command
module spam { export alias ll = ls -l }
module spam { export def foo [] { "foo" } }; use spam foo; foo
module foo { export def-env bar [] { let-env FOO_BAR = "BAZ" } }; use foo bar; bar; $env.FOO_BAR
export extern echo [text: string]
export old-alias ll = ls -l
module spam { export def foo [] { "foo" } }
module eggs { export use spam foo }
use eggs foo
foo
export-env { let-env SPAM = 'eggs' }
export-env { let-env SPAM = 'eggs' }; $env.SPAM
extern echo [text: string]
'nushell' | fill -a l -c '─' -w 15
'nushell' | fill -a r -c '─' -w 15
'nushell' | fill -a m -c '─' -w 15
1 | fill --alignment right --character '0' --width 5
1.1 | fill --alignment center --character '0' --width 5
1kib | fill --alignment middle --character '0' --width 10
[1 2] | filter {|x| $x > 1}
[{a: 1} {a: 2}] | filter {|x| $x.a > 1}
let cond = {|x| $x.a > 1}; [{a: 1} {a: 2}] | filter $cond
ls | find toml md sh
'Cargo.toml' | find toml
[1 5 3kb 4 3Mb] | find 5 3kb
[moe larry curly] | find l
[abc bde arc abf] | find --regex "ab"
[aBc bde Arc abf] | find --regex "ab" -i
[[version name]; ['0.1.0' nushell] ['0.1.1' fish] ['0.2.0' zsh]] | find -r "nu"
[[foo bar]; [abc 123] [def 456]] | find 123 | get bar | ansi strip
[1 2 3] | first
[1 2 3] | first 2
0x[01 23 45] | first 2
[[N, u, s, h, e, l, l]] | flatten
[[N, u, s, h, e, l, l]] | flatten | first
[[origin, people]; [Ecuador, ([[name, meal]; ['Andres', 'arepa']])]] | flatten --all | get meal
[[origin, crate, versions]; [World, ([[name]; ['nu-cli']]), ['0.21', '0.22']]] | flatten versions --all | last | get versions
{ a: b, d: [ 1 2 3 4 ], e: [ 4 3 ] } | flatten d --all
42 | fmt
for x in [1 2 3] { print ($x * $x) }
for $x in 1..3 { print $x }
for $it in ['bob' 'fred'] --numbered { print $"($it.index) is ($it.item)" }
ls | format '{name}: {size}'
[[col1, col2]; [v1, v2] [v3, v4]] | format '{col2}'
ls | format filesize KB size
du | format filesize B apparent
4Gb | format filesize MB