Page 1 of 1 1
Topic Options
#19735 - 2002-04-10 07:29 PM Modification of a TXT file
Anonymous
Unregistered


I was able to use SHOWACLS and a txt file w/ a list of all servers and drives to script some information gathering, now I need to format the txt file to be a CSV to be usable in Excell....

The TXT file looks like the following....

:\sites\QEHO\Europe CPO\2002\monthend\01jan
Everyone Full Control [ALL]

N:\sites\QEHO\Europe CPO\2002\monthend\01jan\CPO Europe
BUILTIN\Administrators Full Control [ALL]
NT AUTHORITY\SYSTEM Full Control [ALL]
QRTP\TSE_HYPERION_IEUR Change [RWXD]
QRTP\TSE_HYPERION_ADMIN Change [RWXD]

N:\sites\QEHO\Europe CPO\2002\monthend\01jan\other
Everyone Full Control [ALL]

so on and so forth (word wrapping may have occured) but in short what I have is line1 = path line2..x (until blank line is found) are the groups and associated permissions...

What I need to do it parse the file and re-write it to be path,groupname,permission

any tips are appreciated!

Top
#19736 - 2002-04-10 08:31 PM Re: Modification of a TXT file
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Im sure (i hope) others will give their interpretation, but here`s a start. Probably will blow-up on the first pass. This is quite a parsing challenge:

Oh yeah, this is kixtart 4.0 (substr)

break on

$filename = "m:\t.dat"

; uncomment for softcopy

; del "out.txt"
; $=redirectoutput("out.txt")

if open(1,$filename) = 0
 $line = readline(1)
 while @error = 0
  if substr($line,2,1) = ":"
   $path = $line
  else
   if $line
    $split = instr($line,"\")
    if $split = 0
     $split = instr($line," ")-1
    else
     $split = $split + instr(substr($line,$split)," ") - 2
    endif
    $group = substr($line,1,$split+1)
    $access = substr($line,$split+1)
   endif
   ?"$path,$group,$access"
  endif
  $line = readline(1)
 loop
 $= close(1)
endif


-Shawn

[ 10 April 2002, 20:32: Message edited by: Shawn ]

Top
#19737 - 2002-04-10 08:54 PM Re: Modification of a TXT file
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Oh yeah, you asked for tips ?

1) Don`t post these kinds of coding challenges on the board during the day. It tends to drive us kixters mad and we don`t get any real work done ! [Wink] heheh

2) Seriously, unless your paths always contain drive letters and colons (?), and if those blank lines of yours before the path are consistent, I would probably recommend you leverage off those in the parsing (instead of the semi-colon like I did).

-Shawn

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.05 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org