need help parsing output
Moderator: DosItHelp
-
- Posts: 129
- Joined: 08 Feb 2016 20:25
Re: need help parsing output
Thanks both of you!
penpen, I'm testing out the code you sent and noticed something - when the first endlocal is processed, it automatically performs a POPD - Is this expeted behavior?
In other words, it seems the popd is unnecessary
penpen, I'm testing out the code you sent and noticed something - when the first endlocal is processed, it automatically performs a POPD - Is this expeted behavior?
In other words, it seems the popd is unnecessary
Re: need help parsing output
That's a clash of different behaviors. You should rather use setlocal/endlocal and pushd/popd in stack (aka LiFo) order.
In this case setlocal-pushd-popd-endlocal.
See
viewtopic.php?t=6187
viewtopic.php?t=4436
In this case setlocal-pushd-popd-endlocal.
See
viewtopic.php?t=6187
viewtopic.php?t=4436
Re: need help parsing output
That was a flaw (sorry):
I've corrected it in my above post; the "popd" should be executed before the first "endlocal" statement.
penpen
I've corrected it in my above post; the "popd" should be executed before the first "endlocal" statement.
penpen
Re: need help parsing output
I have a bit of brain fade these days so I'm just responding to this part as I know you've been using jrepl.
This code parses the lines you've shown below.
icacls doesn't show any trailing whitespace AFAIK.
Edit: I browsed the thread you chatted to Dave in. See here for my view of your complex question viewtopic.php?f=3&t=6108
With simpler information about the folder structure you need to process it would be easier to understand. A small list of folders like this would be useful using the dir /s /b /ad command.
c:\Program Files\WinFast\Common\dtd\MPEG
c:\Program Files\WinFast\WFDTV\fio
c:\Program Files\WinFast\WFDTV\LiveUpdate
c:\Program Files\WinFast\WFDTV\RCConfig
c:\Program Files\WinFast\WFDTV\Services
c:\Program Files\WinFast\WFDTV\vcredist
c:\Program Files\WinRAR\Formats
c:\Program Files\XBasic\bin
c:\Program Files\XBasic\demo
c:\Program Files\XBasic\help
c:\Program Files\XBasic\images
c:\Program Files\XBasic\include
c:\Program Files\XBasic\lib
c:\Program Files\XBasic\templates
c:\Program Files\Yawcam\com
c:\Program Files\Yawcam\extravars
c:\Program Files\Yawcam\img
c:\Program Files\Yawcam\lang
c:\Program Files\Yawcam\lib
c:\Program Files\Yawcam\logs
c:\Program Files\Yawcam\motion
This code parses the lines you've shown below.
Code: Select all
ttype file.txt|jrepl "^.:.*?files |.*? [\t ]" ""
icacls doesn't show any trailing whitespace AFAIK.
Edit: I browsed the thread you chatted to Dave in. See here for my view of your complex question viewtopic.php?f=3&t=6108
With simpler information about the folder structure you need to process it would be easier to understand. A small list of folders like this would be useful using the dir /s /b /ad command.
c:\Program Files\WinFast\Common\dtd\MPEG
c:\Program Files\WinFast\WFDTV\fio
c:\Program Files\WinFast\WFDTV\LiveUpdate
c:\Program Files\WinFast\WFDTV\RCConfig
c:\Program Files\WinFast\WFDTV\Services
c:\Program Files\WinFast\WFDTV\vcredist
c:\Program Files\WinRAR\Formats
c:\Program Files\XBasic\bin
c:\Program Files\XBasic\demo
c:\Program Files\XBasic\help
c:\Program Files\XBasic\images
c:\Program Files\XBasic\include
c:\Program Files\XBasic\lib
c:\Program Files\XBasic\templates
c:\Program Files\Yawcam\com
c:\Program Files\Yawcam\extravars
c:\Program Files\Yawcam\img
c:\Program Files\Yawcam\lang
c:\Program Files\Yawcam\lib
c:\Program Files\Yawcam\logs
c:\Program Files\Yawcam\motion
mirrormirror wrote:I'm asking in the wider forum in case someone might have a solution ising findstr or something.
I want to parse the output from this:Code: Select all
C:\>icacls "c:\Program Files\Common Files"
c:\Program Files\Common Files NT SERVICE\TrustedInstaller:(F)
NT SERVICE\TrustedInstaller:(CI)(IO)(F)
NT AUTHORITY\SYSTEM:(M)
NT AUTHORITY\SYSTEM:(OI)(CI)(IO)(F)
BUILTIN\Administrators:(M)
BUILTIN\Administrators:(OI)(CI)(IO)(F)
BUILTIN\Users:(RX)
BUILTIN\Users:(OI)(CI)(IO)(GR,GE)
CREATOR OWNER:(OI)(CI)(IO)(F)
The only problem I have is the first line of output:Code: Select all
c:\Program Files\Common Files NT SERVICE\TrustedInstaller:(F)
The output I want is this (with all preceeding / trailing <TABS>, <SPACES> trimmed):Code: Select all
NT SERVICE\TrustedInstaller:(F)
NT SERVICE\TrustedInstaller:(CI)(IO)(F)
NT AUTHORITY\SYSTEM:(M)
NT AUTHORITY\SYSTEM:(OI)(CI)(IO)(F)
BUILTIN\Administrators:(M)
BUILTIN\Administrators:(OI)(CI)(IO)(F)
BUILTIN\Users:(RX)
BUILTIN\Users:(OI)(CI)(IO)(GR,GE)
CREATOR OWNER:(OI)(CI)(IO)(F)
Re: need help parsing output
This also removes all leading whitespace.
That path line in your sample text isn't normally there in icacls output is it?
Knowing how you use icacls to get your data is a good way to get the simplest code for your task. < I just saw this and there was a hell of a lot of code and text before it appeared.
Knowing the way your task is generated gives the volunteers the easiest way to help you.
Seeing some foldernames gives good clues too.
Code: Select all
for /f "tokens=*" %%a in ('type file.txt') do echo %%a
That path line in your sample text isn't normally there in icacls output is it?
Knowing how you use icacls to get your data is a good way to get the simplest code for your task. < I just saw this and there was a hell of a lot of code and text before it appeared.
Knowing the way your task is generated gives the volunteers the easiest way to help you.
Seeing some foldernames gives good clues too.
-
- Posts: 129
- Joined: 08 Feb 2016 20:25
Re: need help parsing output
Thanks penpen & aGerman for the info - I've incorporated these updates into my code.
I had a "working" solution when I made these posts (as indicated) but was looking for something better and also looking to learn in the process. My request was just to find a way to parse the icacls output regardless of the folder structure - so I wouldn't have to wory about the naming conventions as I was working on this. As it stands, I think I have a good working solution - thanks to everyone's help. Although, I may ask for some help with code optimization at a later time
As far as giving more information, you are probably right and it would help but sometimes I think looooong posts actually discourage people from reading them - as we all have limited time on our hands. I'll work on providing more info. without being overly wordy...
It is there, but only in the first line of output - that is the line I was asking for advice in how to parse out:That path line in your sample text isn't normally there in icacls output is it?
Code: Select all
C:\>icacls "c:\Program Files\Common Files"
c:\Program Files\Common Files NT SERVICE\TrustedInstaller:(F)
NT SERVICE\TrustedInstaller:(CI)(IO)(F)
.........
Misunderstandings often happen when we make assumptions - and in this case you may be assuming that I actually know what I am doing with icacls when I may, in fact, have no idea - kidding aside... My foder structure is fairly basic at the moment but the problem is that is it not fixed yet - I'm still figuring it out. I'm also not 100% sure how I am going to get to my final goal and I am trying icacls.exe right now and experimenting.Knowing how you use icacls to get your data is a good way to get the simplest code for your task. < I just saw this and there was a hell of a lot of code and text before it appeared.
Knowing the way your task is generated gives the volunteers the easiest way to help you.
Seeing some foldernames gives good clues too.
I had a "working" solution when I made these posts (as indicated) but was looking for something better and also looking to learn in the process. My request was just to find a way to parse the icacls output regardless of the folder structure - so I wouldn't have to wory about the naming conventions as I was working on this. As it stands, I think I have a good working solution - thanks to everyone's help. Although, I may ask for some help with code optimization at a later time
As far as giving more information, you are probably right and it would help but sometimes I think looooong posts actually discourage people from reading them - as we all have limited time on our hands. I'll work on providing more info. without being overly wordy...
Re: need help parsing output
mirrormirror wrote:As far as giving more information, you are probably right and it would help but sometimes I think looooong posts actually discourage people from reading them
Because batch scripting is still a form of programming the best way to get code that is robust and efficient is to state what you need to do, and if needed include the tools you'd prefer to use or state which ones you can't use.
Then let the programmers decide the best way to handle the job.
Try running this code in "c:\program files" or some other folder tree and when you see the pause go and check your desktop for file.txt
Code: Select all
@echo off
(for /r /d %%a in (*) do pushd "%%a" &echo "folder = %%a" & (
for /f "tokens=* delims=. " %%b in ('icacls . ^|find /v /i "Successfully processed" ') do echo %%b
) & popd )>"%userprofile%\desktop\file.txt"
pause
I am not sure what you need to do but this lists the permissions and an extra line to show the folder - and it can be modified in many ways depending on your need.
-
- Posts: 129
- Joined: 08 Feb 2016 20:25
Re: need help parsing output
foxdrive, I tried out the code and it appears to work! I was skeptical that it could handle folders with special characters but my "test folder" passed:
Thank you for taking the time to write this up. Also, I completely forgot about the "for /r" option and did not even realize that you could combine "/r" and "/d" - I'll make a note of these.
And to expand on what I'm working on - The code I posted here gives an idea:
viewtopic.php?f=3&t=7305&#p48029
This code here is just a building block. My larger goal is to have a general startup script on several systems which will create links to network shared folders on the users desktop. So I thought I might search for all of the folders which certain localgroups have access to. That's what this line is doing:
Then parse those ICACLS privs for only the users/groups I choose and stick those in a database.
The startup script would check this database to see which folders the user has access to and automatically create desktop links.
Those are my thoughts anyway, but I'm still trying to decide if this is the best way to go about it. I've had some free time this week to tinker with it but starting tomorrow my free time will be limited for a while so I'll have to come back and revisit it.
One more note: All of this is on a local workgroup - not a domain. The file-server is win7 and/or xp so there are certain restrictins on connections, etc. I've found there are good tools for managing users/privs on a domain, but to automate these things in a "localgroup" setting can sometimes be tedious.
Code: Select all
"folder = T:\aT1\1% 2% 3% 4^% 5% ) == & =. a! b! c! d^! e! ^ ^ 'n1 = n +2 -( )))"
BUILTIN\Administrators:(I)(F)
BUILTIN\Administrators:(I)(OI)(CI)(IO)(F)
NT AUTHORITY\SYSTEM:(I)(F)
NT AUTHORITY\SYSTEM:(I)(OI)(CI)(IO)(F)
NT AUTHORITY\Authenticated Users:(I)(M)
NT AUTHORITY\Authenticated Users:(I)(OI)(CI)(IO)(M)
BUILTIN\Users:(I)(RX)
BUILTIN\Users:(I)(OI)(CI)(IO)(GR,GE)
Thank you for taking the time to write this up. Also, I completely forgot about the "for /r" option and did not even realize that you could combine "/r" and "/d" - I'll make a note of these.
And to expand on what I'm working on - The code I posted here gives an idea:
viewtopic.php?f=3&t=7305&#p48029
This code here is just a building block. My larger goal is to have a general startup script on several systems which will create links to network shared folders on the users desktop. So I thought I might search for all of the folders which certain localgroups have access to. That's what this line is doing:
Code: Select all
FOR /F "tokens=1,* delims=:" %%a IN ('icacls "%NetResRoot%" /findsid "%tagFldr01%" /t /c /l ^|FIND /I "SID Found:"') DO (
Then parse those ICACLS privs for only the users/groups I choose and stick those in a database.
The startup script would check this database to see which folders the user has access to and automatically create desktop links.
Those are my thoughts anyway, but I'm still trying to decide if this is the best way to go about it. I've had some free time this week to tinker with it but starting tomorrow my free time will be limited for a while so I'll have to come back and revisit it.
One more note: All of this is on a local workgroup - not a domain. The file-server is win7 and/or xp so there are certain restrictins on connections, etc. I've found there are good tools for managing users/privs on a domain, but to automate these things in a "localgroup" setting can sometimes be tedious.
Re: need help parsing output
mirrormirror wrote:And to expand on what I'm working on - The code I posted here gives an idea:
viewtopic.php?f=3&t=7305&#p48029
So I thought I might search for all of the folders which certain localgroups have access to. That's what this line is doing:Code: Select all
FOR /F "tokens=1,* delims=:" %%a IN ('icacls "%NetResRoot%" /findsid "%tagFldr01%" /t /c /l ^|FIND /I "SID Found:"') DO (
Then parse those ICACLS privs for only the users/groups I choose and stick those in a database.
The task is not too clear mirrormirror and further details will make this thread far shorter, and make it an easier slog for the helpers.
I gather that:
1) You're getting the sid from someplace and the usergroups from someplace, and filtering certain users in some way.
2) You want to detect some user permission in a folder and then put these all in a file.
With some information about these things then the entire task can be assessed and woven together - which usually ends up more efficient and simpler too.
Disguise the exact details you need to keep private but leave the format and length of names and things, and let the peeps here stick some elbow grease into the task.
I've already said my bit and I'm just commenting that piecemeal adjusting of code is not very satisfying for the helpers. It's seeing an overview of a task and then coding to get the job done - is what many helpers find enjoyable.
-
- Posts: 129
- Joined: 08 Feb 2016 20:25
Re: need help parsing output
I've already said my bit and I'm just commenting that piecemeal adjusting of code is not very satisfying for the helpers. It's seeing an overview of a task and then coding to get the job done - is what many helpers find enjoyable.
I guess you could split my proccess into two parts. 1: data declaration and gathering, 2: data usage.
I consider the 1st part to be about done - at least it is functional. There needs to be cleanup and one more minor task but none of that is difficult. This is the part where I was asking for a better way to parse my "icacls" output - and you guys helped me out.
The 2nd part - I am not quite ready to tackle at the moment.
As it stands, the 1st script is over 100K - but probably half of that is embedded data and helper utilities - so maybe 50K of code. That is a lot to ask of a volunteer to slog through. And it is pretty much one big proccess with a lot of working pieces. I can't really post a subset or demo of working code because of the dependencies - so it is everything or nothing if you want to see a working model.
So this is not a work project - it is simply a hobby project to help make managing my home network easier. I would welcome assistance with the project as a whole but it would take me maybe a whole day to do a proper write-up of it with current code, etc. That's a big time-commitment on my part and I have no clue if any of you guys actually have the time to tacke something like this.
If any of you are really interested in tackling this let me know.
Re: need help parsing output
mirrormirror wrote:As it stands, the 1st script is over 100K - but probably half of that is embedded data and helper utilities - so maybe 50K of code. That is a lot to ask of a volunteer to slog through.
My comment was about describing the aim of the script, not about posting your code.