need some help with data

Started by pamsniffer, May 13, 2015, 03:23:52 AM

Previous topic - Next topic

pamsniffer

Hi,

I have a text file with the following records

"Administrator";"Administrators   (Builtin/domain.com);  group1 (Users//domain.com)"
"Admin";"Administrators   (Builtin/domain.com);  group1 (Users/domain.com); group2 (remote/domain.com); Admin  (Builtin/domain.com)"

Is it possible to make a new file  according to way

"Administrator","Administrators   (Builtin/domain.com)"
"Administrator","group1 (Builtin/domain.com)"
"Admin";"Administrators   (Builtin/domain.com)"
"Admin"; "group1 (Users/domain.com)"
"Admin"; "group2 (remote/domain.com)"
"Admin"; "Admin  (Builtin/domain.com)"


PAM

JTaylor

Sure.   Take a look at the FileRead() and FileWrite() functions in the documentation and it will provide an example for reading.  Then take a look at the For/Next function.   You will also want ItemExtract(), StrTrim() and StrCat()

Just read through the file grabbing each line, Extract the first element using ItemExtract() and the ";" as the delimiter and pass the rest through the For Loop joining the first element with each subsequent element and write it to a new file.

Fairly straightforward.


Jim

pamsniffer


JTaylor

There was  a bit of inconsistency in the delimiters you used so I went with ";".   The following should get you started.

Jim

Code (winbatch) Select



or = FileOpen("pamsniffer.txt", "READ")
ow = FileOpen("pamsniffer_new.txt", "WRITE")


count = 0
While @TRUE ; Loop till break do us end
   line = FileRead(or)
   If line == "*EOF*" Then Break
   uname = ItemExtract(1,line,";")
   For x = 2 to ItemCount(line,";")
     itxt = StrTrim(ItemExtract(x,line,";"))
     FileWrite(ow,uname:";":itxt)
   Next
EndWhile

FileClose(ow)
FileClose(or)