locked
Replace Word RRS feed

  • Question

  • Guys , 

    I would like to Replace  word : DWH_SRC_ID           CHAR(4)                        not null title 'Source',  into empty . Can you please share me any commands to do . I tried with below commands it shows error for me any ideas please let me know 

    PS Y:\> (Get-Content Y:\ke.txt) | Foreach-Object {$_ -replace 'DWH_SRC_ID           CHAR(4)                        not null title 'Source',', ' '} | Set-Content Y:\ke1.txt
    At line:1 char:124
    + ...      CHAR(4)                        not null title 'Source',', ' '} | ...
    +                                                         ~~~~~~~~~
    Unexpected token 'Source','' in expression or statement.
    At line:1 char:133
    + ...     CHAR(4)                        not null title 'Source',', ' '} |  ...
    +                                                                 ~
    Missing argument in parameter list.
        + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
        + FullyQualifiedErrorId : UnexpectedToken

    • Moved by Bill_Stewart Monday, July 29, 2019 7:33 PM Abandoned
    Tuesday, October 9, 2018 9:17 AM

All replies

  • To remove a string:

    $_ -replace 'your string'

    No need for any other items.

    Example:

    PS D:\scripts> 'this is a string in here' -replace ' a string'
    this is in here
    PS D:\scripts>


    \_(ツ)_/

    • Proposed as answer by taylor.l Wednesday, October 10, 2018 2:46 PM
    Tuesday, October 9, 2018 9:36 AM
  • You have a very strange string which you want to replace. It also contains quotes so using that right into your code will mess stuff up.

    If you make a variable first with that string it's a lot easier to read aswell.

    $string = "DWH_SRC_ID           CHAR(4)                        not null title 'Source'"
    Get-Content Y:\ke.txt | ForEach-Object { $_.Replace($string,"")  }

    It should work better like this.


    Tuesday, October 9, 2018 1:18 PM