none
how to edit a text-file using Powershell

    Question

  • Need to replace all the words in the text "project" on "project_demo". Using Powershell recently.
    Tuesday, June 14, 2011 1:16 PM

Answers

  • (gc file.txt) -replace "\bproject\b","project_demo" > result.txt



    • Marked as answer by yagorik Tuesday, June 14, 2011 2:02 PM
    Tuesday, June 14, 2011 1:19 PM
  • the -replace is a regex command

    www.regular-expressions.info

    \b - Matches at the position between a word character (anything matched by \w) and a non-word character (anything matched by [^\w] or \W) as well as at the start and/or end of the string if the first and/or last characters in the string are word characters.

    basically saying whole word matches only, not part of a word.

    • Marked as answer by yagorik Tuesday, June 14, 2011 2:03 PM
    Tuesday, June 14, 2011 1:56 PM

All replies

  • (gc file.txt) -replace "\bproject\b","project_demo" > result.txt



    • Marked as answer by yagorik Tuesday, June 14, 2011 2:02 PM
    Tuesday, June 14, 2011 1:19 PM
  • the -replace is a regex command

    www.regular-expressions.info

    \b - Matches at the position between a word character (anything matched by \w) and a non-word character (anything matched by [^\w] or \W) as well as at the start and/or end of the string if the first and/or last characters in the string are word characters.

    basically saying whole word matches only, not part of a word.

    • Marked as answer by yagorik Tuesday, June 14, 2011 2:03 PM
    Tuesday, June 14, 2011 1:56 PM
  • Thank you very much!
    Tuesday, June 14, 2011 2:04 PM