mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-02 23:27:45 +00:00
Add duplicates script
This commit is contained in:
parent
c0fe250a43
commit
9b5d54947d
2 changed files with 35 additions and 0 deletions
22
duplicates/duplicates.nu
Normal file
22
duplicates/duplicates.nu
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# duplicates returns the rows that correspond to duplicates of the given column.
|
||||||
|
def duplicates [
|
||||||
|
column: string # Column to look duplicates at
|
||||||
|
--count(-c) # set it to display the number of times the value is repeated.
|
||||||
|
] {
|
||||||
|
group-by $column |
|
||||||
|
pivot |
|
||||||
|
insert count { = $it.Column1 | flatten | count} |
|
||||||
|
where count > 1 |
|
||||||
|
reject Column0 |
|
||||||
|
if $(= $count | empty?) {reject count} {each {=$it}} |
|
||||||
|
flatten |
|
||||||
|
flatten
|
||||||
|
}
|
||||||
|
|
||||||
|
# duplicates files recursively finds duplicate files in the current working folder.
|
||||||
|
# It uses a heuristic based on duplicate files having the same size.
|
||||||
|
def "duplicates files" [] {
|
||||||
|
do -i {ls **/*} | duplicates size
|
||||||
|
}
|
||||||
|
|
||||||
|
|
13
duplicates/example.nu
Normal file
13
duplicates/example.nu
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# duplicates example
|
||||||
|
echo $info | from json
|
||||||
|
let info = "[{name: "John", lastname: "Doe"}, {name: "John", lastname: "Roe"}, {name: "Jane", lastname: "Soe"}]"
|
||||||
|
echo $info | from json | duplicates name
|
||||||
|
|
||||||
|
#duplicates files example
|
||||||
|
echo A | save A.txt
|
||||||
|
echo A | save B.txt
|
||||||
|
# note that if I used "echo B | save B.txt" the function will give a false positive
|
||||||
|
echo ABC | save C.txt
|
||||||
|
ls
|
||||||
|
duplicates files
|
||||||
|
rm A.txt B.txt C.txt --permanent
|
Loading…
Add table
Add a link
Reference in a new issue