Hi all,
I'll just start by saying this forum is really great and contains some much information, keep up the good work!
Back to the action: I'm trying to reformat the output of a MS tool (sysinternals) called 'accesschk'. It can be used to generate an overview of directory structures and their permissions.
Tool output example:
c:\Users\Default
RW NT AUTHORITY\SYSTEM
RW BUILTIN\Administrators
R BUILTIN\Users
R Everyone
c:\Users\Test User
R Everyone
RW NT AUTHORITY\SYSTEM
RW BUILTIN\Administrators
I want to reformat it to a delimited file where each lines contains the folder, followed by the user followed by the permission. Let me reformat the example.
Desired ouput:
c:\Users\Default;NT AUTHORITY\SYSTEM;RW
c:\Users\Default;BUILTIN\Administrators;RW
c:\Users\Default;BUILTIN\Users;R
c:\Users\Default;Everyone;R
c:\Users\Test User;Everyone;R
c:\Users\Test User;NT AUTHORITY\SYSTEM;RW
c:\Users\Test User;BUILTIN\Administrators;RW
I tried this:
awk 'BEGIN{OFS=";"} !/^ / {f=$0} /^ / { print f, $0}' test.txt
This is the logic I used:
If a line does not start with a double space, it contains the folder name, so we store it in a variable f and don't print the line. If the line do starts with a double space, it contains a permission, so print the last folder name we have, a semicolon and the current line.
But it seems it prints the folder name and then overwrites the same line with the current. So this is the output:
; RW NT AUTHORITY\SYSTEM
; RW BUILTIN\Administrators
; R BUILTIN\Users
; R Everyonelt
; R EveryoneUser
; RW NT AUTHORITY\SYSTEM
; RW BUILTIN\Administrators
If anyone can point me in the right direction, it would make me a happy man!
Thanks in advance.
Kerbje