Text Processing in Windows

shunmare

shun

Posted on August 12, 2023

Text Processing in Windows

Searching within Text

  • findstr: Search for strings in files.

    • /I: Ignore case.
    • /S: Searches for matching files in the current directory and all subdirectories.
    • /V: Print only lines that do not contain a match.
    C:\> findstr "search_term" file.txt
    This line contains the search_term.
    
```bash
C:\> findstr /I "Search_Term" file.txt
This line contains the search_term.
```
Enter fullscreen mode Exit fullscreen mode

Filtering and Transforming Text

  • There's no direct equivalent to awk in Windows, but you can use PowerShell or other scripting languages for similar tasks.

  • powershell -Command "(Get-Content file.txt) -replace 'World', 'Universe'": Use PowerShell to replace text.

  C:\> echo Hello World | powershell -Command "$input -replace 'World', 'Universe'"
  Hello Universe
Enter fullscreen mode Exit fullscreen mode

Sorting and Counting

  • sort: Sort input.
  C:\> echo banana & echo apple & echo cherry | sort
  apple
  banana
  cherry
Enter fullscreen mode Exit fullscreen mode
  • There's no direct uniq equivalent in Windows, but you can use PowerShell for similar tasks.
  • find /c /v "": Count lines in a file.
  C:\> echo Hello World | find /c /v ""
  1
Enter fullscreen mode Exit fullscreen mode

Text Display

  • type: Display the content of files.
  C:\> type file.txt
  This is the content of file.txt.
Enter fullscreen mode Exit fullscreen mode
  • There's no direct tac equivalent in Windows, but you can use PowerShell for similar tasks.
  • more +n: Display content starting from the nth line. (Similar to tail)
  C:\> echo line1 & echo line2 & echo line3 | more +1
  line2
  line3
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
shunmare
shun

Posted on August 12, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related