Skip to main content

Posts

Powershell Commands useful for large CSV files

1) To get the header line, ie: first row in a CSV file  gc .\FILENAME.csv -TotalCount 1 2) To get the header line, and export it to another CSV file.  Note the use of Set-Content rather than Export-CSV gc .\FILENAME.csv -TotalCount 1 | Set-Content .\header-file-name.csv 3) To filter the CSV file based on a regex search , and export the matches to another file. gc .\FILENAME.csv | Select-String -Pattern ( '.*2018-11-20.*' ) | Set-Content .\inner-file-name.csv 4) To see the last few lines, like tail  gc .\20181206_InteractionDetails.csv | select -last 10

Some find commands - useful for copying iCloud Photos to another service.

I've found these commands really helpful when navigating an iCloud Photo library on a Mac. The native Photos Application on MacOS prohibits a lot of bulk file activity.  These commands should be run from Terminal. Before starting, it's best to place yourself in the following directory "/Users/**your username**/Pictures/Photos Library.photoslibrary" This command is best executed from the "Masters" directory  find . -iname  *.cr2  -exec ls -lh {} \; It finds all CR2 files and reports the file sizes   You could change the ls to a copy, say to copy the image to another folder, like another cloud drive.  Find all file types outside a defined list, and filter those only in the Masters directory find . -iname *.* | grep Masters | grep -v -i -E '\.jpg|\.jpeg|\.heic|\.png|\.cr2|\.gif|\.mp4'  Find all file types IN a defined list, and filter those only in the Masters directory find . -iname *.* | grep M...