You are not logged in.
I am no coder, by any means, unless you consider html code....I don't
any how, here's what i'm trying to do, if someone who knows bash would like to assist?
i have a folder, with a bunch of subfolders, inside these subfolders, is a setup.xml file.
and inside these setup xml files is a line titled product code with a string after it.
i could really use a script or sorts to go through and output all those product codes into a single text file right now, otherwise i'm sure i'll be here for hours
anyone care to help?
this is a signature
Offline
Without an example of the file, it is difficult to help. But you could try
grep -R 'product code' yourfolder/ > outputfile.txt
This will only work if "product code: string" is the only thing on that line, and it won't separate out the string. You could use awk for that...
Offline
In bash 4 or later (or in zsh) it's as simple as the following line, given that "xmlstarlet" is installed (available in the AUR iirc) and that the product code is available in a tag called "ProductCode" anywhere in the XML document.
xmlstarlet sel -t -v //ProductCode **/setup.xml
It shouldn't be difficult to adapt this line to your needs. If you have further problems, we'll need exact examples of your data files.
Last edited by lunar (2012-04-09 23:56:19)
Offline
hmmm, that might just be a start
here's an example maybe of the struction
rootfolder1/setupfiles/setup.xml
rootfolder2/setupfiles/32/setup.xml
rootfolder2/setupfiles/64/setup.xml
rootfolder3/setupfiles/setup.xml
basically, I work for a company, and i'm trying to make some removal tools for our software. i can make a windows batch file because its simply a list of commands, i can make similar shell scripts, but for the type of scripting i'm looking for here to help me parse the data faster, its a little over my head
as long as I can get the strings into a text file, i can then do a replace all "{" with "command /x {" in notepad or something
this is a signature
Offline
hmmm, that might just be a start
here's an example maybe of the struction
rootfolder1/setupfiles/setup.xml
rootfolder2/setupfiles/32/setup.xml
rootfolder2/setupfiles/64/setup.xml
rootfolder3/setupfiles/setup.xmlbasically, I work for a company, and i'm trying to make some removal tools for our software. i can make a windows batch file because its simply a list of commands, i can make similar shell scripts, but for the type of scripting i'm looking for here to help me parse the data faster, its a little over my head
as long as I can get the strings into a text file, i can then do a replace all "{" with "command /x {" in notepad or something
I think you need to study up before you go loosely changing things without knowing exactly what your doing.
Offline
^ no need, I know what i'm doing.
i'm simply extracting windows installer package strings to make a manual removal tool for those times when the uninstall doesn't do its job properly.....which happens too much. and then people get errors trying to reinstall stating that the program is already installed because of 1 msi file stuck in the installer cache. its gravy business.
i'm just looking for an easy way to extract the strings from our xmls into a single file to make the task a little less intricate.
this is a signature
Offline
#!/bin/bash
for f in "$(find . -type f -name '*.xml')"
do
grep "product code" $f >> myList
done
## optionally use sed or awk to clean up myList here
#sed -i 's/regex_to_delete//' myList
Edit: this is untested. Sometimes passing the results of a find to a for loop takes some care. This may do ridiculous things. This may make your car break down and your dog run away. Or it might just do what you need.
Last edited by Trilby (2012-04-10 01:40:23)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
thanks trilby, ill give it a shot
lucky for me I don't have a car to break down, or a dog to run away
this is a signature
Offline
find /your/folder -name \*.xml -exec grep 'product code' '{}' \; > theFile
You could get fancy and not redirect the output, but rather pipe it through sed and create some streaming rules. One would need to know more about the file structure to build that incantation.
Last edited by ewaller (2012-04-10 01:53:23)
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
ooooh.......that works
tweaked it a bit and ran it from the source folder, worked well, this is what i ran though
find -name \Setup.xml -exec grep 'productcode' '{}' \; > theFile
does this give you any idea as to the file structure of the xmls?
<Setups productcode="ICA.productcode">
<Msi productcode="UpdateX3.exe" file="WPO15\UpdateX3.exe" cmdline="/s" adminsupport="0" condition="UpdateX3=1"/>
<Msi productcode="{6E274E81-F9E1-43A2-9672-E45F655953FA}" file="WPO15\UpgradesX4.msi" cmdline="ADDLOCAL=ALL" progresstext="Str.UpgradeProgressText" adminsupport="0" condition="REMOVE_14" scheduled="0" ignorereturn="1" />
<Msi productcode="{DCDAB2ED-5741-4C30-A1A4-0FCB8A529001}" file="ICA_X4.msi" cmdline="REMOVE=ALL" progresstext="Str.UpgradeProgressText" adminsupport="0" condition="REMOVE_14" scheduled="0" ignorereturn="1" />
<Msi productcode="{92B60B3B-7DF3-4BF7-8823-9F17A9EEA31E}" file="WPO15\Setup.msi" progresstext="Str.ProgressText.Common" cmdline="ICA_ALL_PUBLIC" managed="1">
<Dbm productcode="{71D2F8EE-9D45-4D95-A6F6-F6433C2B94B5}" file="WPO15\ENSystem.msi" progresstext="Str.ProgressText.Common" adminsupport="0"/>
<Dbm productcode="{EC61C6D9-159B-4B14-AAF3-AF33FCFA50DD}" file="WPO15\ENWP.msi" cmdline="ADDVIEWERS=[ADDVIEWERS]" progresstext="Str.ProgressText.WP" />
<Dbm productcode="{DAEDCD3D-B981-4F10-B17B-764753EDAF9F}" file="WPO15\ENQP.msi" progresstext="Str.ProgressText.QP" />
<Dbm productcode="{378BAC91-3AE8-45F0-90E4-4F81E3EAEBC5}" file="WPO15\ENPR.msi" progresstext="Str.ProgressText.PR" />
<Dbm productcode="{17C5A285-F7B6-492B-8F3B-343D02B84D75}" file="WPO15\ENCommon.msi" progresstext="Str.ProgressText.Common" cmdline="ESTIMATEDSIZE=[ICA.DiskSpace.Drive.Required.0] PIDPREFIX=WP15" />
<Dbm productcode="{D7643510-C1AE-44AD-B0F9-0665C4D73BFD}" file="WPO15\LegalTools.msi" progresstext="Str.ProgressText.WP" />
<Dbm productcode="{CD5C6C29-E6CB-4DF3-B45F-A04087B1C294}" file="WPO15\ENTemplates.msi" progresstext="Str.ProgressText.WP" />
<Dbm productcode="{E67732DE-3387-4F1E-BDDA-2D0C08BC025B}" file="WPO15\ENFilters.msi" progresstext="Str.ProgressText.Common"/>
<Dbm productcode="{6E4B1E42-A831-44B4-A705-D006F68560EC}" file="WPO15\ENGraphics.msi" progresstext="Str.ProgressText.Common"/>
<Dbm productcode="{19B4CD07-1919-4002-B28F-A5D2027026E0}" file="WPO15\IPM.msi" progresstext="Str.ProgressText.Common" cmdline="PCUSOURCEID=[PCUSOURCEID] ALLOW_PRODUCTUPDATES="[ALLOW_PRODUCTUPDATES]" SERIALNUMBER="[SERIALNUMBER]" USERNAME="[USERNAME]" SHOW_EULA=[AcceptLicense] SKU=[SKU]"/>
<Dbm productcode="{E539B721-4458-4EFC-8BD0-04D4842051AE}" file="WPO15\EN.msi" progresstext="Str.ProgressText.EN" cmdline="SKUDATA="[SKUDATA]"" />
<Dbm productcode="{D4167D08-0F61-4F44-BC3F-26B4960745C4}" file="WPO15\ENSkins.msi" progresstext="Str.ProgressText.EN" />
<Dbm productcode="{64459BD5-3AE8-4689-B7B0-D57B667D8399}" file="WPO15\ENPExp.msi" progresstext="Str.ProgressText.Common" />
<Dbm productcode="{1F0D7D15-8A36-4AE4-8573-70BEA7DF379D}" file="WPO15\MMan_EN.msi" progresstext="Str.ProgressText.Common" />
Last edited by ssl6 (2012-04-10 02:05:44)
this is a signature
Offline
find /your/folder -name \*.xml -exec grep 'product code' '{}' \; | cut -d \= -f 2 | cut -d ' ' -f 1 |cut -d \" -f2
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
awk -F\" '/{/ { gsub(/[{}]/,""); print $2 }'
Offline
awk -F\" '/{/ { gsub(/[{}]/,""); print $2 }'
I first saw awk around 1982. 30 years later, I still have no clue what that spell does.
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
It's an elegant way of dealing with this:
cut -d \= -f 2 | cut -d ' ' -f 1 |cut -d \" -f2
#edit: to provide a more complete answer:
for file in $(find yourdir/ -name "*xml"); do awk -F\" '/{/ { gsub(/[{}]/,""); print $2 }' <"$file" ; done > outputfile.txt
Last edited by jasonwryan (2012-04-10 03:02:56)
Offline
oh you guys are awesome. this will work for me.
so far this is what I have for my bat/cmd file. just need to add specifics to it and break it down for each application
i probly don't need both the del and rd commands in there, rd would be sufficient, but just in case. resetting the directory permissions is not likely necessary either, but just in case. resetting the windows installer components key is a must since we tend to run into a lot of 1402 errors
@echo off
echo resetting directory permissions
subinacl /subdirectories %programfiles%\path\ /grant=administrators=f /grant=system=f /grant=users=e >> %temp%\subinacl_output.txt
subinacl /subdirectories %appada%\path\ /grant=administrators=f /grant=system=f /grant=users=e >> %temp%\subinacl_output.txt
echo resetting Windows installer components registry key permissions
subinacl /subkeyreg HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\ /grant=administrators=f /grant=system=f /grant=users=r /grant=everyone=r /grant=restricted=r /setowner=administrators >> %temp%\subinacl_output.txt
echo Adding registry policy for additional windows installer logs
reg add HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v Logging /d voicewarmupx /f
reg add HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v Debug /t REG_DWORD /d 00000007 /f
echo Running uninstall processes
msiexec /x productcodes /passive
msiexec /x productcodes /passive
msiexec /x productcodes /passive
msiexec /x productcodes /passive
msiexec /x productcodes /passive
msiexec /x productcodes /passive
msiexec /x productcodes /passive
msiexec /x productcodes /passive
echo Removing remaining Program Files folders
del "%programfiles(x86)%\path" /S /F /Q
rd "%programfiles(x86)%\path" /S /Q
del "%programfiles(x86)%\Common Files\path" /S /F /Q
rd "%programfiles(x86)%\Common Files\path" /S /Q
del "%programfiles%\path" /S /F /Q
rd "%programfiles%\path\" /S /Q
del "%programfiles%\Common Files\path\" /S /F /Q
rd "%programfiles%\Common Files\path\" /S /Q
echo Removing remaining application data
rd %appdata%\path /S /Q
rd %appdata%\pathcad /S /Q
echo removing registry keys
reg delete HKCU\SOFTWARE\path /f
reg delete HKLM\SOFTWARE\path /f
reg delete HKLM\SOFTWARE\Wow6432Node\path /f
reg delete HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /f
echo Creating log file directory
md %HOMEDRIVE%%HOMEPATH%\desktop\install-log
echo copying log files for review
copy %temp%\msi*.log %HOMEDRIVE%%HOMEPATH%\desktop\install-log\
copy %temp%\subinacl_output.txt %HOMEDRIVE%%HOMEPATH%\desktop\install-log\
i really need to learn more about bash though, there are times it would help me soooo much
Last edited by ssl6 (2012-04-10 03:22:16)
this is a signature
Offline
Arch Forums - providing solutions for Windows admins since four hours ago.
Offline
Arch Forums - providing solutions for Windows admins since four hours ago.
LMAO
this is a signature
Offline
for file in $(find yourdir/ -name "*xml"); do awk -F\" '/{/ { gsub(/[{}]/,""); print $2 }' <"$file" ; done > outputfile.txt
Okay, I get it I am starting to understand awk !
so why not:
find yourdir/ -name \*.xml -exec awk -F\" '/{/ { gsub(/[{}]/,""); print $2 }' \{\} \; > outputfile.tex
???
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
I thought the loop would handle multiple *.xml files better (but that is as much based on ignorance as it is on a pathological fear of escaping multiple special characters in long find commands)...
Offline