none
Replace string in the log file RRS feed

  • Question

  • Hello everyone,

    I really suck with Powershell scripting. I'm trying to replace string in a log file, I was able to replace one part of the string that I want to replace with and the remaining part I just can't figure it out.

    I have several string with &X-ARR-LOG-ID=xxxxxxxxxxxxxx (the xxx are 36 characters in length that including number, letter, and hyphen. It generates randomly  by IIS), I was able to replace &X-ARR-LOG-ID= but can't replace for part after =. 

    I would really appreciate if anyone can help me with this.

    Thanks in advance.



    dtng




    • Edited by dtng Friday, October 14, 2016 3:11 AM
    Friday, October 14, 2016 3:08 AM

Answers

  • Use replace with this pattern:

    '&X-ARR-LOG-ID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' -replace '&X-ARR-LOG-ID=.{36}','abcdefghijklmno'


    \_(ツ)_/

    • Marked as answer by dtng Friday, October 14, 2016 4:54 AM
    Friday, October 14, 2016 3:54 AM
  • '&X-ARR-LOG-ID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' -replace 'X-ARR-LOG-ID=.{36}','abcdefghijklmno'

    \_(ツ)_/

    • Marked as answer by dtng Sunday, October 16, 2016 4:52 PM
    Saturday, October 15, 2016 6:22 PM

All replies

  • Use replace with this pattern:

    '&X-ARR-LOG-ID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' -replace '&X-ARR-LOG-ID=.{36}','abcdefghijklmno'


    \_(ツ)_/

    • Marked as answer by dtng Friday, October 14, 2016 4:54 AM
    Friday, October 14, 2016 3:54 AM
  • You're rock, JRV. Thank you very very much. :). I really appreciated. 

    dtng

    Friday, October 14, 2016 4:54 AM
  • You are welcome.  Have fun.

    \_(ツ)_/

    Friday, October 14, 2016 5:13 AM
  • Hi jrv,

    I was able to replaced/removed X-ARR-LOG-ID=a2764ed8-1e61-43d9-9a62-a37d8144ffff 80 - and added hyphen (-) before 80.

    I have been trying to remove & (I highline in bold) Type=Recipe&X-ARR-LOG-ID=a2764ed8-1e61-43d9-9a62-a37d8144ffff 80 but unable to.

    Search for: " X-ARR-LOG-ID=[^&]+ "

    Replace with: " - "


    Search for: "&X-ARR-LOG-ID=[^&]+ "

    Replace with: " "

    Neither one above work. 

    I really appreciate if you can help me with this.

    Thank you in advance.


    dtng


    • Edited by dtng Saturday, October 15, 2016 4:38 PM
    Saturday, October 15, 2016 4:27 PM
  • I don't understand your issue.  My code removes hat character.


    \_(ツ)_/

    Saturday, October 15, 2016 5:05 PM
  • Sorry, using your remove/replace code I was able to remove X-ARR-LOG-ID=49c7f82e-7abb-47f7-a9c2-b36bbeea4087

    I was trying to remove & before X but can't figure out.

    There are several line in the log have &X-ARR-LOG-ID=49c7f82e-7abb-47f7-a9c2-b36bbeea4087 80, I want to remove the & along with X-ARR-LOG-ID=49c7f82e-7abb-47f7-a9c2-b36bbeea4087 

    If i used &X-ARR-LOG-ID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' -replace '&X-ARR-LOG-ID=.{36}','abcdefghijklmno', it will leave the X-ARR-LOG-ID untouch.



    dtng


    • Edited by dtng Saturday, October 15, 2016 6:21 PM
    Saturday, October 15, 2016 6:20 PM
  • '&X-ARR-LOG-ID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' -replace 'X-ARR-LOG-ID=.{36}','abcdefghijklmno'

    \_(ツ)_/

    • Marked as answer by dtng Sunday, October 16, 2016 4:52 PM
    Saturday, October 15, 2016 6:22 PM
  • Thanks a lot, jrv. It works as expected.

    dtng

    Sunday, October 16, 2016 4:52 PM
  • Hi jrv,

    I have looked around but couldn't find the answer. Can you use Powershell If / Else statement to check for if log file exists in Azure blob storage URL?

    Thanks,


    dtng

    Thursday, October 20, 2016 3:11 AM