Skip to main content

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

Comments

Popular posts from this blog

NMAP

It's been about 15 years since I used NMAP, I forgot how useful the tool is. To find out what services are running on an IP address simply use something like nmap -n -v -p1-10000 x.x.x.x -n tells nmap not to do name resolution (saves about 13 seconds if the IP you're scanning isn't in DNS_ -v verbose -p1-10000 says scan ports 1 to 10,000 (otherwise nmap will only scan the first 1000 ports)