ShellSpells
  • 🧙‍♂️Welcome!
    • ShellSpells
    • FAQs
    • License & Disclaimer
  • 🐧Linux
    • System Ops
      • Transcripts
      • Help
      • System Info
        • Date/Time
        • System Details
        • Patches & Updates
        • Init System Identification
        • Hostname / Host ID
        • Variables
        • Hardware & Resources
      • Filesystem
        • Traverse & Enumerate
        • Drives & Partitions
        • Shares
        • Packages
        • Connected Devices
        • Kernel Modules (Drivers)
      • Users & Groups
        • Enumerate
        • Modify
      • Network
        • Enumerate
        • Modify
      • Scheduled Jobs
        • Enumerate
        • Modify
      • Processes
        • Enumerate
        • Modify
        • Custom Script and Shared Object
        • Process I/O Redirection
      • Services
        • Enumerate
        • Modify
        • Create a Service
      • Startup/Boot Scripts
        • Enumerate
        • Modify
      • Security
        • Antivirus
        • Firewall
        • SSH Keys
      • History & Logs
        • History
        • Logs
    • File Ops
      • Search
        • Filename
        • Content
        • Users (Owners)
        • Time
        • Size
        • Permission
        • Hidden Files
        • Inode
        • Find + Exec
        • Notes
      • Enumerate Metadata
      • Modify Metadata
      • Read Content
      • Modify Content
      • Extract Content
      • Sort / Compare / Count
      • Move
      • Copy
      • Execute
      • Hash
      • Encode/Decode
      • Compress/Decompress
      • Working With Weird Filenames
    • Terminal Ops
      • Keyboard Shortcuts
      • Tmux Shortcuts
  • 🪟Windows
    • System Ops
      • Transcripts
      • Help
      • System Info
        • One-liners
        • Date/Time
        • System Details
        • Hotfixes
        • Domain or Workgroup
        • Data Execution Prevention
        • Variables
        • Hardware & Resources
      • Filesystem
        • Traverse & Enumerate
        • Drives & Partitions
        • Installed Software
        • Drivers
        • Shares
      • Registry
        • Enumerate
        • Modify
        • Forensically Relevant Keys
      • Users & Groups
        • Enumerate
        • Modify
      • Network
        • Enumerate
        • Modify
      • Scheduled Tasks
      • Processes
        • Enumerate
        • Modify
      • Services
        • Enumerate
        • Modify
      • Autorun / Startup
        • Enumerate
        • Modify
      • Security
        • Permissions
          • Enumerate
          • Page
        • Antivirus
        • Firewall
          • Enumerate
          • Modify
        • Audit Policies
        • Remoting
          • Enumerate
          • Modify
          • Registry Locations
        • Stored Credentials
      • Remote Command Execution
      • Active Directory
        • Enumerate
        • Modify
      • History & Logs
        • History
        • Logs
      • PowerShell Config
      • Scripting
      • WMIC Notes
    • File Ops
      • Search
        • Filename
        • Time
        • Size
        • Permissions
        • Attributes
        • Wildcarding
      • Enumerate Metadata
        • One Liners
        • Users (Owners)
        • Timestamps
        • Size
        • Permissions
        • Attributes
      • Modify Metadata
        • Change Owner
        • Timestamps
        • Size
        • Attributes
      • Read Content
      • Modify Content
        • Overwrite
        • Insert
        • Append
        • Replace / Remove
        • Convert Case
        • Alternate Data Streams
      • Extract Content
      • Sort / Compare / Count
        • Sort
        • Count
        • Compare
      • Move
      • Copy
      • Execute
      • Hash
      • Encode/Decode
      • Compress/Decompress
      • Working With Weird Filenames
      • Output Formatting / Filtering
      • File Formatting
      • Operators
  • ⛓️Network
    • Traffic Manipulation
      • iptables
        • Option List
        • General Commands
        • Filter Tables
        • NAT
        • Mangle
        • Filter for SSH Traffic (Example)
      • nftables
    • Packet Capture
      • Syntax
      • TCPDump Examples
    • Packet Analysis
      • Wireshark
  • 🚗Maneuver
    • SSH
    • Control Sockets
    • RDP
    • Windows Port Proxy
  • 🛩️Data Transfer
    • SCP
    • FTP
    • Netcat
      • Netcat Relays
    • Server Interactions
    • Alternate Methods
  • 🪄REGEX
    • Examples
Powered by GitBook
On this page
  • Pattern Match
  • Line Numbers
  • Unique / Deduplicate

Was this helpful?

  1. Windows
  2. File Ops

Extract Content

Pattern Match

find /i "keyword" file.txt

Find text, case-insensitive.

sls -path [file] -pattern [string]

Find strings in a file (PowerShell)

select-string -path [file] -pattern [string]

Find strings in a file (PowerShell)

Select-String -path c:\\users \\\*.txt –pattern password

Find strings in a file (PowerShell)

findstr "pattern" C:\path\to\file.txt

Find matching lines (CMD)

type C:\path\to\file.txt | findstr "pattern"

Find matching lines (CMD)

Get-Content file.txt | Select-String -Pattern "keyword"

Find strings in a file (PowerShell)

Find text within a file:

gci -recurse c:\\users -file | % {Select-String -path $ \_ -pattern password}

Search a file's contents for Polo. This also splits the file from one line to a newline for each word:

((Get-Content .\countpolos).split(" ")) | select-string \bpolo\b 

Filter lines that contain a specific string:

Get-Content C:\path\to\file.txt | Where-Object { $_ -match "specific string" } | Set-Content C:\path\to\filteredfile.txt

Don't forget to use -ErrorAction SilentlyContinue

Line Numbers

Displays the content of a file starting from the 11th line:

more +10 C:\file.txt

Unique / Deduplicate

Remove duplicate lines from a file:

Get-Content C:\path\to\file.txt | Sort-Object | Get-Unique | Set-Content C:\path\to\uniquefile.txt

Reads the file, sorts the lines, removes duplicates, and saves the result to a new file using PowerShell.

Get-Content C:\path\to\file.txt | Sort-Object | Get-Unique | Set-Content C:\path\to\outputfile.txt 

Filters lines matching a specific pattern, removes duplicates, and saves to a new file using PowerShell.

(Get-Content C:\path\to\file.txt) -match 'pattern' | Select-Object -Unique | Set-Content C:\path\to\filteredfile.txt 

For CSV files, sorts entries based on a specific column, removes duplicates, and saves the result to a new CSV file using PowerShell.

Import-Csv C:\path\to\file.csv | Sort-Object -Property ColumnName -Unique | Export-Csv C:\path\to\outputfile.csv -NoTypeInformation

Groups lines, identifies duplicates, selects one occurrence of each duplicate, and saves the result using PowerShell.

Get-Content C:\path\to\file.txt | Group-Object | Where-Object { $_.Count -gt 1 } | ForEach-Object { $_.Group | Select-Object -First 1 } | Set-Content C:\path\to\outputfile.txt
PreviousAlternate Data StreamsNextSort / Compare / Count

Last updated 1 year ago

Was this helpful?

🪟