Sign in to follow this  
Followers 0
ter-pierre

a while inside a while ! ! !

5 posts in this topic

Hi guys

I have 2 files

with 2 fields each one

first file : ID,USERNAME

second file: USERMANE.GROUPMEMBER

I need to read the first file, line by line, and find, in second file, all lines that i have the same user. At finish i need a file with ID,USERNAME,GROUPMEMBER

I´m trying with the code above...

$file1=FileOpen("C:\tmp1-4.txt",0)

$file2=FileOpen("C:\tmp1-2.txt",0)

While 1

$CAD_USER=FileReadLine($FILE2)

If @error = -1 Then ExitLoop

$SPLIT=StringSplit($CAD_USER,",")

$CADASTRO=$SPLIT[1]

$USER=$SPLIT[2]

While $USER<>"END_FILE"

$USER_GRP=FileReadLine($FILE1)

If @error = -1 Then ExitLoop

$SPLIT2=StringSplit($USER_GRP,";")

$USER1=$SPLIT2[1]

$GROUP=$SPLIT2[2]

If $USER=$USER1 Then FileWriteLine("C:\TMP3-1.TXT",$CADASTRO&"|"&$USER&"|"&$GROUP)

WEnd

WEnd

My problem is that is running fine just for the first user from tmp1-2.txt. for the other lines the second while/wend apears not functional.

Thanks for your help. :lmao:

Share this post


Link to post
Share on other sites



First tell us if this is what you want.

If NOT we'll look further into this.

$file1=FileOpen("C:\tmp1-4.txt",0)
$file2=FileOpen("C:\tmp1-2.txt",0)
While 1
   $CAD_USER=FileReadLine($FILE2)
   If @error = -1 Then ExitLoop
   $SPLIT=StringSplit($CAD_USER,",")
   $CADASTRO=$SPLIT[1]
   $USER=$SPLIT[2]
   If $USER <> "END_FILE" Then
      $USER_GRP=FileReadLine($FILE1)
      If @error = -1 Then ExitLoop
      $SPLIT2=StringSplit($USER_GRP,";")
      $USER1=$SPLIT2[1]
      $GROUP=$SPLIT2[2]
      If $USER=$USER1 Then FileWriteLine("C:\TMP3-1.TXT",$CADASTRO&"|"&$USER&"|"&$GROUP)
   EndIf
WEnd

Share this post


Link to post
Share on other sites

not exactly

my file tmp1-2 are a list of all my domain users, generated by CSVDE exporting samaccountname and description fields

my file tmp1-4 are a list genetated by grptest.exe command, reworked to contain at each line USERNAME,GROUPNAME.

I need to put together those 2 files using the USERNAME

Share this post


Link to post
Share on other sites

Allright.

1. You split each line of tmp1-2 you said in the last post that tmp1-4 contains lines with a comma.

Is it a typo or a mistake?

2. What about this? "$USER=$SPLIT[2]"

I thought you said: "contain at each line USERNAME,GROUPNAME"

To match what you said:

$USER=$SPLIT[1]
   $CADASTRO=$SPLIT[2]

I updated your script.

$file1_handle=FileOpen("C:\tmp1-2.txt",0)
$file3_handle=FileOpen("C:\TMP3-1.TXT", 2)
While 1
   $CAD_USER=FileReadLine($file1_handle)
   If @error = -1 Then ExitLoop
   $SPLIT=StringSplit($CAD_USER,",")
   $USER=$SPLIT[1]
   $CADASTRO=$SPLIT[2]
    $file2_handle=FileOpen("C:\tmp1-4.txt",0)
   While 1
      $USER_GRP=FileReadLine($file2_handle)
      If @error = -1 Then ExitLoop
      $SPLIT2=StringSplit($USER_GRP,";")
      $USER1=$SPLIT2[1]
      $GROUP=$SPLIT2[2]
      If $USER=$USER1 Then FileWriteLine($file2_handle,$CADASTRO&"|"&$USER&"|"&$GROUP)
   EndIf
   FileClose($file2_handle)
WEnd
FileClose($file1_handle)
FileClose($file3_handle)

Share this post


Link to post
Share on other sites

Thanks for your attention, but dont work. The result is that TMP3-1 contains information s just for the first user listed on tmp1-2.

But i found a way...

$file2=FileOpen("C:\tmp1-2.txt",0)

While 1

$CAD_USER=FileReadLine($FILE2)

If @error = -1 Then ExitLoop

$SPLIT=StringSplit($CAD_USER,",")

$CADASTRO=$SPLIT[1]

$USER=$SPLIT[2]

GRUPO($USER)

WEnd

Exit

Func GRUPO($USER)

$file1=FileOpen("C:\tmp1-4.txt",0)

While 1

$USER_GRP=FileReadLine($FILE1)

If @error = -1 Then ExitLoop

$SPLIT2=StringSplit($USER_GRP,";")

$USER1=$SPLIT2[1]

$GROUP=$SPLIT2[2]

If $USER=$USER1 Then FileWriteLine("C:\TMP3-1.TXT",$CADASTRO&"|"&$USER&"|"&$GROUP)

WEnd

FileClose($file1)

EndFunc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0