AutoHotkey Community

It is currently May 27th, 2012, 3:33 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: July 4th, 2010, 9:47 pm 
Offline

Joined: July 2nd, 2010, 11:25 pm
Posts: 16
No one should get upset with my question even if it's so simple and stupid to you'll...I am a finance guy trying to write a script...."so new"

@little Fairy, I've been trying to understand your code for the past few hours and I am having to read and understand every command to see what it means....tedious but I am learning a lot....Still don't understand all the lines of code yet....

Anyways i need to make adjustment to the code....Line 1 on file A doesn't always correspond to Line 1 on File B.....File B is the mapping file. I need to take the value in A and search for its equivalent in B before replacing it.

Thanks, for your help


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2010, 7:18 am 
Quote:
Anyways i need to make adjustment to the code....Line 1 on file A doesn't always correspond to Line 1 on File B.....File B is the mapping file. I need to take the value in A and search for its equivalent in B before replacing it.
that´s exactly what the code does!
Why don´t you just try the script??


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2010, 3:48 pm 
Offline

Joined: July 2nd, 2010, 11:25 pm
Posts: 16
@little Fairy...
I tried it, at first it seems like it was changing the wrong ones.....but that was my mistake......YOU ARE THE MAN!

Thanks so much!!!!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 6th, 2010, 8:50 pm 
Offline

Joined: July 2nd, 2010, 11:25 pm
Posts: 16
@little Fairy...
how do I adjust the code so it stops adding "|" after each line? I've tried for hours trying to adjust the code but it seems I can only get it to remove"|" after each colon.

Can you help me out?

Code:
#Include tf.ahk

;TF_TrimRight("!atest2.csv","","",5)

FileSelectFile, files, M3, , Open one or more "atest"s ;files stores the upload file.
if files =
    ExitApp

FileSelectFile, LookupFile, 3, , Open the "btest", ;LookupFile stores the map file.
if LookupFile =
    ExitApp

FileSelectFolder, OutputFolder, , 3 ;stores the new upload file.
if OutputFolder =
    ExitApp

   
Loop, parse, files, `n
{
    if a_index = 1
        Path := A_LoopField
    else
    {
       Currentfile := Path . "\" . A_LoopField
       FileRead, atest, %Currentfile%
       FileRead, btest, %LookupFile%
       OutputFile =
       gosub, Exchange ;jump to exchange function
       OutFileName := OutputFolder . "\" . A_Loopfield
       FileAppend, %OutputFile%, %OutFilename%

    }
}
MsgBox, Done
return

Exchange:
loop, parse, atest, `n, `r
{
   StringSplit, CurrentField, A_Loopfield ,|
   Loop, parse, btest, `n, `r
   {
      IfInString, A_Loopfield, %CurrentField2%
      {
         StringSplit, CurrentReplacement, A_Loopfield ,|
         CurrentField2 := CurrentReplacement2
         break
      }
   }
   loop, %CurrentField0%
      CurrentLine .= CurrentField%A_Index% . "|"
   OutputFile .= CurrentLine . "`r`n "
   CurrentLine =
   }


return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 7th, 2010, 7:10 am 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
So you have this
Quote:
20100517|L00015099|97001GP|1||||||

and want this
Quote:
20100517|L00015099|97001GP|1

:?:
A simple
Code:
stringreplace, outputfile, outputfile, ||||||, , All

should do it

StringReplace wrote:
Replaces the specified substring with a new string.
Source: http://www.autohotkey.com/docs/commands ... eplace.htm


if it is just the extra trailing | just trim it before appending it to the outfile like so by changing this
Code:
loop, %CurrentField0%
      CurrentLine .= CurrentField%A_Index% . "|"
   OutputFile .= CurrentLine . "`r`n "
   CurrentLine =

to
Code:
loop, %CurrentField0%
      CurrentLine .= CurrentField%A_Index% . "|"
   stringtrimright, CurrentLine, CurrentLine, 1 ; remove trailing |
   OutputFile .= CurrentLine . "`r`n "
   CurrentLine =

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 7th, 2010, 4:07 pm 
Offline

Joined: July 2nd, 2010, 11:25 pm
Posts: 16
@hugov
Thanks a lot, it's amazing what you can do with this! I wish I was good as you guy!....But I'm learning a lot so far.

I wanted to remove all the trailing | but I tried inserting

stringreplace, outputfile, outputfile, ||||||, , All

after the file creating but it didn't seem to work. I always ended with ||

So I went with your last idea but changed 1 to 2 and also kept the
TF_TrimRight("!atest2.csv","","",5)


Code:
loop, %CurrentField0%
      CurrentLine .= CurrentField%A_Index% . "|"
   stringtrimright, CurrentLine, CurrentLine, 2 ; remove trailing |
   OutputFile .= CurrentLine . "`r`n "
   CurrentLine =


It's working perfectly thank you!

Another questions....

What if instead of replacing the middle column in file a I want to replace the third colon? I have tried changing the value in %CurrentField0% but still not working....any ideas please....

Thanks!!!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 7th, 2010, 4:16 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Probably change 2 to 3 here
Code:
Loop, parse, btest, `n, `r
   {
      IfInString, A_Loopfield, %CurrentField3%
      {
         StringSplit, CurrentReplacement, A_Loopfield ,|
         CurrentField2 := CurrentReplacement3
         break
      }

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 7th, 2010, 4:57 pm 
Offline

Joined: July 2nd, 2010, 11:25 pm
Posts: 16
i tried that, and it's not working...it actually just erases column 2 in file A.....
I was thinking I had to change something in
Code:
StringSplit, CurrentField, A_Loopfield , |
   Loop, parse, btest, `n, `r

I could be wrong!!!



I want to replace column C in file A with column B from file File B

File A

20100517|L00014977|97001GP|1
20100517|L00015024|97001GP|1
20100517|L00015081|97530GP|4


File B

97001GP|4200010
97001GP|4200012
97530GP|4200013


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 7th, 2010, 5:48 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
hugov wrote:
Probably change 2 to 3 here
Code:
Loop, parse, btest, `n, `r
   {
      IfInString, A_Loopfield, %CurrentField3%
      {
         StringSplit, CurrentReplacement, A_Loopfield ,|
         CurrentField[b]2[/b] := CurrentReplacement3
         break
      }
Sorry forgot a 2 see blue 2

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 7th, 2010, 6:14 pm 
Offline

Joined: July 2nd, 2010, 11:25 pm
Posts: 16
@hugov
perfect!
I changed one more thing; CurrentReplacement to 2....and it's working nice

Code:
IfInString, A_Loopfield, %CurrentField3% ;field that's been referenced
      {
         StringSplit, CurrentReplacement, A_Loopfield ,|
         CurrentField3 := CurrentReplacement2 ;currentfield been replaced
         break
      }



Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, Wicked, Yahoo [Bot] and 14 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group