1.

Solve : help with cmd script?

Answer»

hello
i just have a quick question
is there a way or a script trough cmd
that can take some data in a line and put it in other line
like this:

boris


is there a way to take the boris name and paste it in


so it will look like this
boris
boris

and for multiple cases if theres multiple
name of someone

and under that theres an empty


it will look for the data in and place the variable in
in the whole file


thanks.
download gawk for windows, then  use this gawk script

Code: [Select]BEGIN{ FS="[<>]" }
/<name>/{ name=$3 }
/<vir_name>/{ $0="<vir_name>"name"</vir_name>" }
{print}
save as myscript.awk, and on command line

Code: [Select]C:\test>type file
<name>boris</name>
<vir_name></vir_name>
blah
<name>becker</name>
<vir_name></vir_name>
blah

C:\test>gawk -f myscript.awk file
<name>boris</name>
<vir_name>boris</vir_name>
blah
<name>becker</name>
<vir_name>becker</vir_name>
blah

redirect using ">" to save to a new file as desired. Quote from: ghostdog74 on April 21, 2010, 03:21:17 AM

download gawk for windows, then  use this gawk script

Code: [Select]BEGIN{ FS="[<>]" }
/<name>/{ name=$3 }
/<vir_name>/{ $0="<vir_name>"name"</vir_name>" }
{print}
save as myscript.awk, and on command line

Code: [Select]C:\test>type file
<name>boris</name>
<vir_name></vir_name>
blah
<name>becker</name>
<vir_name></vir_name>
blah

C:\test>gawk -f myscript.awk file
<name>boris</name>
<vir_name>boris</vir_name>
blah
<name>becker</name>
<vir_name>becker</vir_name>
blah

redirect using ">" to save to a new file as desired.

thanks for the reply but specifically this i can do with simple cmd script
what i am looking for is a script that will be more dynamic

if i am working on an xml file and have multiple properties in there and the property names are
blabla
and i also have a property


i would want it to fill every value that in in to
and there can be a dynamic number of properties
and the property is already in the xml file
so i dont need to create it
i just need to insert the data from in to Quote
thanks for the reply but specifically this i can do with simple cmd script
what i am looking for is a script that will be more dynamic

More dynamic than what? If you already have a simple cmd script, why are you not using it?

Microsoft provides an object (actually two) for traversing the nodes in a XML file, however yours is ill-formed and would choke a VBScript. For instance, judging from your post, <name> and <vir_name> are siblings. What is the parent node?  Where do <DISPLAY_NAME> and <CANONICAL_NAME> logically fit into the tree? Is there a root to the tree and if so what is it.

Personally I don't find Gawk to be very intuitive, but it WORKS and sometimes you need brute force instead of dynamic.

  Quote from: Sidewinder on April 22, 2010, 05:48:03 AM
More dynamic than what? If you already have a simple cmd script, why are you not using it?

Microsoft provides an object (actually two) for traversing the nodes in a XML file, however yours is ill-formed and would choke a VBScript. For instance, judging from your post, <name> and <vir_name> are siblings. What is the parent node?  Where do <DISPLAY_NAME> and <CANONICAL_NAME> logically fit into the tree? Is there a root to the tree and if so what is it.

Personally I don't find Gawk to be very intuitive, but it works and sometimes you need brute force instead of dynamic.

 

hi, i have a script that does what the gawk script above but i dont really need it in most situations
for example i have properties in some xml

       
           
            4
            Hello
           
            1
            0
            0
           
            1
           
            1
            11111111
           
           
           
           
           
       

these are most situation and the properties are build that way so what i need is
a script that will take 'Hello' from and paste it in
so the FINAL file will look like that

       
            Hello
            4
            Hello
           
            1
            0
            0
           
            1
           
            1
            11111111
           
           
           
           
           
       

putting manually a possible situation in the script will force me to write a wall of scripting
and i have numerous properties in the xml that the structure are the same as above but only the property_id changes and the labeling values
so what i need is that it will go trough the file and put value in
thats pretty much it...

thanks I had to add a ROOT node to the tree structure. The root node ties the entire file together.

Quote
<?xml version="1.0"?>
<ROOT>
   <PROPERTY>
      <CANONICAL_NAME>Hello</CANONICAL_NAME>
      <CURRENT_STATE>4</CURRENT_STATE>
      <DISPLAY_NAME>Hello</DISPLAY_NAME>
      <FORMAT_STRING></FORMAT_STRING>
      <IS_COMPUTED>1</IS_COMPUTED>
      <IS_MANAGED>0</IS_MANAGED>
      <IS_MULTI_VALUED>0</IS_MULTI_VALUED>
      <IS_PCODE></IS_PCODE>
      <IS_STRING>1</IS_STRING>
      <IS_URI></IS_URI>
      <LOCALE_ID>1</LOCALE_ID>
      <PROPERTY_ID>11111111</PROPERTY_ID>
      <STORAGE_UNIT></STORAGE_UNIT>
      <TIP_TEXT></TIP_TEXT>
      <VALUE_SORT_TYPE></VALUE_SORT_TYPE>
      <VIEWBY_UNIT></VIEWBY_UNIT>
      <MANAGED_PROPERTY_VALUES></MANAGED_PROPERTY_VALUES>
   </PROPERTY>
   <PROPERTY>
      <CANONICAL_NAME>Goodbye</CANONICAL_NAME>
      <CURRENT_STATE>4</CURRENT_STATE>
      <DISPLAY_NAME>Goodbye</DISPLAY_NAME>
      <FORMAT_STRING></FORMAT_STRING>
      <IS_COMPUTED>1</IS_COMPUTED>
      <IS_MANAGED>0</IS_MANAGED>
      <IS_MULTI_VALUED>0</IS_MULTI_VALUED>
      <IS_PCODE></IS_PCODE>
      <IS_STRING>1</IS_STRING>
      <IS_URI></IS_URI>
      <LOCALE_ID>1</LOCALE_ID>
      <PROPERTY_ID>11111111</PROPERTY_ID>
      <STORAGE_UNIT></STORAGE_UNIT>
      <TIP_TEXT></TIP_TEXT>
      <VALUE_SORT_TYPE></VALUE_SORT_TYPE>
      <VIEWBY_UNIT></VIEWBY_UNIT>
      <MANAGED_PROPERTY_VALUES></MANAGED_PROPERTY_VALUES>
   </PROPERTY>
</ROOT>

Code: [Select]Set xmlDoc = CREATEOBJECT("Microsoft.XMLDOM")

xmlDoc.Async = "False"
xmlDoc.Load("c:\temp\test.xml")          'Change as needed (input XML file)

Set colDisplayNodes=xmlDoc.documentElement.selectNodes("/ROOT/PROPERTY/DISPLAY_NAME")
For Each displayNode in colDisplayNodes
  Set colCanonNodes = xmlDoc.documentElement.selectNodes _
  ("/ROOT/PROPERTY " & _
"[DISPLAY_NAME = " & "'" & displayNode.text & "'" & "]/CANONICAL_NAME")
  For Each canonNode In colCanonNodes
     canonNode.text = displayNode.text
  Next
Next

xmlDoc.Save "c:\temp\Testout.xml"         'Change as needed (output XML file)

Save the file with a VBS extension and run from the command prompt as cscript scriptname.vbs Can also be run from a cmd file the same way.

Good luck. 

The XMLDOM object will realign your XML file correctly. No extra charge.


Discussion

No Comment Found