Ved at bruge denne side, du accepterer Privatlivspolitik.
Acceptere
EnterineEnterineEnterine
  • HJEM
  • Det pro
  • Teknik
  • Microsoft
    • Azurblå
    • Configmgr/SCCM
    • DPM
    • Orkester
    • Hyper-V
    • Microsoft Edge Insider
    • MSI
    • Kontor 365
    • Office Insider
    • Power BI
    • Skype
    • SQL Server
    • Hold
  • Windows
    • Windows Admin Center
    • Windows klient
    • Windows Server
  • SCCM-forespørgselsindsamlingsliste
Læsning: PowerShell extract strings from a file
Font ResizerAa
EnterineEnterine
Font ResizerAa
  • HJEM
  • Det pro
  • Teknik
  • Microsoft
  • Windows
  • SCCM-forespørgselsindsamlingsliste
Søge
  • HJEM
  • Det pro
  • Teknik
  • Microsoft
    • Azurblå
    • Configmgr/SCCM
    • DPM
    • Orkester
    • Hyper-V
    • Microsoft Edge Insider
    • MSI
    • Kontor 365
    • Office Insider
    • Power BI
    • Skype
    • SQL Server
    • Hold
  • Windows
    • Windows Admin Center
    • Windows klient
    • Windows Server
  • SCCM-forespørgselsindsamlingsliste
PowerShell

PowerShell extract strings from a file

Offentliggjort: februar 18, 2024
1 Min læst
DELE

PowerShell extract strings from a file.

To extract only strings from a file using PowerShell, you can use the Select-String cmdlet.

Here’s an example command to extract strings from a file:

Get-Content path/to/file.txt | Select-String -Pattern '\b\w+\b'

In this example, path/to/file.txt is the path to the file you want to extract strings from. De Get-Content cmdlet reads the file and outputs its content as an array of strings. De Select-String cmdlet then searches for strings that match the regular expression pattern \b\w+\b, which matches any word character (letters, digits, and underscores) surrounded by word boundaries. The output of the Select-String cmdlet is a collection of MatchInfo objects that contain the matching strings.

If you want to output just the matching strings (without the MatchInfo objects), you can pipe the output to the ForEach-Object cmdlet and use the $_.Matches.Value property to extract the matching strings, like this:

Get-Content path/to/file.txt | Select-String -Pattern '\b\w+\b' | ForEach-Object { $_.Matches.Value }

This will output only the matching strings from the file.

TAGGET:PowerShellWindowsWindows 10Windows Server 2016Windows Server 2019Windows Terminal
Forrige artikel Configuration Manager Forespørgselsindsamlingsliste Configuration Manager Forespørgselsindsamlingsliste
Næste artikel Command Line Tips: Checking TLS/SSL Certificate Expiration Dates
Efterlad en kommentar Efterlad en kommentar

Efterlad et svar Annuller svar

Din e-mailadresse vil ikke blive offentliggjort. Påkrævede felter er markeret *

Denne side bruger Akismet til at reducere spam. Lær, hvordan dine kommentardata behandles.

Oversættelse

English中文(简体)DanskNederlandsFrançaisDeutschItaliano한국어PolskiPortuguêsRomânăEspañolУкраїнська
ved Transposh - translation plugin for wordpress

Populære indlæg

Systemkrav til Windows Server 2016
Windows Server
Configuration Manager Forespørgselsindsamlingsliste
Configuration Manager Forespørgselsindsamlingsliste
Configmgr
Struktureret/administreret navigation aktiveret på moderne sider i klassiske teamwebsteder
Teknik
SCCM Kunne ikke hente DP-placeringer som den forventede version fra MP
Configmgr

Seneste indlæg

Installation og konfiguration af Fail2ban til SSH-beskyttelse på Ubuntu 24.04
Linux
Aktivering og konfiguration af FirewallD på AlmaLinux
Linux
Brugeroprettelse og SSH-nøgleopsætning i AlmaLinux
Linux
Sådan nulstiller du adgangskoden på AlmaLinux
Linux

© 2023 Enterine

Gå til mobil version
Velkommen tilbage!

Log ind på din konto

Brugernavn eller e-mail-adresse
Adgangskode

Mistet din adgangskode?