Find and Replace String

25 pts.
Tags:
SQL
String
How to find complete string e.g I have 2 strings in a file "TABLE" and "TABLE_NAME". I want to replace "TABLE" with "COLUMN" and "TABLE_NAME" with "TAB_NAME". My current script replaces "TABLE_NAME" with "COLUMN_NAME", which is not what I want.

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • carlosdl
    So, you want to do this using SQL, right?
    On what database (Oracle, SQL Server, DB2, etc)?

    Can you post your current script?

    You could try replacing "TABLE_" with "TAB_" first, and then replacing TABLE with COLUMN.
    84,310 pointsBadges:
    report
  • shrikantbothe

    No, I am using Windows Powershell Scripting. Here is my script:

    $csv = Import-Csv D:\Temp\old_new_names.csv
    $xmlfiles = Get-ChildItem D:\Temp\*.xml

    foreach ($line in $csv)
    {
     foreach ($file in $xmlfiles)
     {
      #Write-Host $file 
      (gc $file) -replace $line.old_name, $line.new_name | Out-File $file -Encoding "ASCII"
     }
    }

    In my "old_new_names.csv", there are 2 columns old_name and new_name. I wish to replace old_name with new_name. In this file if old_name = TABLE and new_name for the same is COLUMN. Then there is another line having old_name = TABLE_NAME which has new_name = TAB_NAME. But when my script gets executed it replaces TABLE with COLUMN. So TABLE_NAME becomes COLUMN_NAME, which is not what I want.

    Hope you understood my exact problem.

    Thanks in advance.

     

    25 pointsBadges:
    report
  • shrikantbothe

    Hello Windows Powershell Scripting experts,

    Is there no solution for finding and replacing complete word in powershell scripting? Pl. read my problem described above.

    25 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: