I am trying to run a powershell script, which will replace the occurrence of a string with another string. I want to remove the angular brackets from the include and replace them with double quotes with the header file name only, without the folder path before the Header file name. Example :
#include <a/b/c/def.hpp>
#include <a/b/c/ddd.hpp>
to
#include "def.hpp"
#include "ddd.hpp"
I have tried this.
(Get-ChildItem -Recurse | Get-Content | Select-String -Pattern "#include <a/b/c/")-replace '#include <a/b/c/(\w+).*/', '#include "'-replace '>','"'
With this, I get the desired result, but I am not able to use the result and replace the existing line in the source file.
Thanks in advance.
I have to query upto 100 files in a folder. Please suggest the best way to do this.
INPUT
#include <a0/b/c/d/HeaderFile1.hpp>
#include <a1/b/c/d/HeaderFile2.hpp>
#include <a2/b/c/d/HeaderFile3.hpp>
#include <a3/b/c/d/HeaderFile4.hpp>
#include <a4/b/c/d/HeaderFile5.hpp>
#include <a5/b/c/d/HeaderFile6.hpp>
OUTPUT
#include "HeaderFile1.hpp"
#include "HeaderFile2.hpp"
#include "HeaderFile3.hpp"
#include "HeaderFile4.hpp"
#include "HeaderFile5.hpp"
#include "HeaderFile6.hpp"