1.

Solve : change text in XML files?

Answer»

that little batch snippet i wrote is all you need to change all xml files under the directory passed using sed. what more is it you require? in fact , i added the for loop only for doing recursive searching, otherwise if your xml files are all in one directory, then  this is all you need.
Code: [Select]sed -i.bak "s/old/new/g" *.xml
Actually, from the looks of that code, it will take all the .xml files from a directory and perform the word switch for each. (But I don't have sed, so ghostdog will need to confirm my thoughts) Quote from: Helpmeh on March 24, 2010, 06:37:01 AM

Actually, from the looks of that code, it will take all the .xml files from a directory and perform the word switch for each. (But I don't have sed, so ghostdog will need to confirm my thoughts)
see reply 15 Quote from: ghostdog74 on March 24, 2010, 06:38:52 AM
see reply 15
Sorry, you must have GOTTEN in right before me, lol... Quote from: ghostdog74 on March 24, 2010, 06:36:22 AM
Code: [Select]sed -i.bak "s/old/new/g" *.xml


The above sed does not work. The original xml file remains the same

Example:

C:\batch>type ghost24.bat
Code: [Select]echo off
Rem The sed change is displayed to the screen only
rem The original xml remains unchanged
echo type envmig.xml
type  envmig.xml

sed  "s/newfile.xml/new/g" envmig.xml

echo type envmig.xml
type  envmig.xml
Output:

C:\batch>ghost24.bat
type envmig.xml
newfile.xml
new
type envmig.xml
newfile.xml
C:\batch>it remains unchanged because you did not redirect to a new file or use -i.
sed by default doesn't change files.
please look at my code again and compare it to yours. Its totally different. Why do you produce different code and say it does not work. ? Quote from: ghostdog74 on March 24, 2010, 09:56:40 AM
it remains unchanged because you did not redirect to a new file or use -i.
sed by default doesn't change files.
please look at my code again and compare it to yours. Its totally different. Why do you produce different code and say it does not work. ?

Ghost,

Thanks for your help.

I must have a different version of sed than you do.

I cannot get my sed to work with your code.


C:\batch>sed -i.bak "s/HKCU/new/g" envmig.xml
Unknown OPTION "-i.bak"
Usage: sed [-nE] [script] [-e script] [-f scriptfile] [file ...]

C:\batch>

______________________________


C:\batch>type   envmig.xml  |  more
http://www.microsoft.com/migration/1.0/migxmlext/oobeupgrade">

 
    oobeUpgrade
   
      %WINDIR%\oobeUpgrade
   
   

     
       
         
            MigXmlHelper.IsOSLaterThan("NT","6.0.0.0")

         
       
       
         
           
              MigXmlHelper.DoesObjectExist("REGISTRY",
"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders [My
Music]")
           
           
              MigXmlHelper.IsSameStringContent...
.
.
.why are you using crippled sed?? see reply 13 on where to download GNU sed.  All my *nix tools are from GNU, not mks. and its free.. Quote from: ghostdog74 on March 24, 2010, 11:44:09 AM
why are you using crippled sed?? see reply 13 on where to download GNU sed.  All my *nix tools are from GNU, not mks. and its free..

Please show me the output for your sed.

sed -i.bak "s/old/new/g" *.xml
it doesn't take 5 minutes to download and try it out yourself. Quote from: ghostdog74 on March 24, 2010, 11:54:30 AM
It doesn't take 5 minutes to download and try it out yourself.

The gnu sed did work:
sed -i.bak "s/HKCU/new/g" envmig.xml

The redirection is implicit with -i.bak.  envmig.xml.bak is created in the same directory.  Then envmig.xml.bak  is copied over envmig.xml.  The changes to envmig.xml appear to occur in place.

One line of sed code to replace the long batch file above.

Command line arguments could be used for "old" and "new".  Then the sed
code sed -i.bak "s/old/new/g" would not need to be changed each time.

Output:

C:\batch>c:\bin\sed -i.bak "s/HKCU/new/g" envmig.xml


C:\batch>type  envmig.xml  | more
http://www.microsoft.com/migration/1.0/migxmlext/oobeupgrade">

 
    oobeUpgrade
   
      %WINDIR%\oobeUpgrade
   
   

     
       
         
            MigXmlHelper.IsOSLaterThan("NT","6.0.0.0")

         
       
       
         
           
              MigXmlHelper.DoesObjectExist("Registry",
"new\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders [My M
usic]")
           
           

Input:

C:\batch>type  envmig.xml |  more
http://www.microsoft.com/migration/1.0/migxmlext/oobeupgrade">

 
    oobeUpgrade
   
      %WINDIR%\oobeUpgrade
   
   

     
       
         
            MigXmlHelper.IsOSLaterThan("NT","6.0.0.0")

         
       
       
         
           
              MigXmlHelper.DoesObjectExist("Registry",
"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders [My
Music]")
           
           
              MigXmlHelper.IsSameStringContent Quote from: GREG on March 24, 2010, 02:47:23 PM
One line of sed code to replace the long batch file above.
EXACTLY! Ghost said that a the top of the page in reply #15! Quote from: Helpmeh on March 24, 2010, 06:37:01 AM
Actually, from the looks of that code, it will take all the .xml files from a directory and perform the word switch for each. (But I don't have sed, so ghostdog will need to confirm my thoughts)

If Helpmeh does not have have sed then Helpmeh was unable to test the code. Helpmeh doesn't test the code or show output.

Helpmeh wrote: (post #26 )
"EXACTLY! Ghost said that a the top of the page in reply #15!"


Discussion

No Comment Found