topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday December 6, 2024, 2:27 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Script for replace any substring in a text file accodring a csv data file  (Read 8140 times)

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Script for replace any substring in a text file accodring a csv data file

Replace or add substring to a text file according a csv file.

Best Regards
 :-*

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,832
    • View Profile
    • Donate to Member
more detail needed, eg what criteria would you use to determine whether to add or replace

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,629
    • View Profile
    • Donate to Member
Despite its name, my tool Excel2Html can be used for this exercise, if the .csv file is converted (loaded) into a .xls or .xlsx file.
And a .html template is plain text, of course.

Relevant DC threads (original Coding snack request and support-thread) are available from the link.

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
more detail needed, eg what criteria would you use to determine whether to add or replace

Two options then :
1. The first one where do you want to insert

2. The second option replace is more simple : I have to select or indicate the substring to be replaced in the original files.

The original files are always inside a folder.


Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Despite its name, my tool Excel2Html can be used for this exercise, if the .csv file is converted (loaded) into a .xls or .xlsx file.
And a .html template is plain text, of course.

Relevant DC threads (original Coding snack request and support-thread) are available from the link.

I'll take a look. But I think better a dedicated tool.

Best Regards Ath
 :-*

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
I think a script of this must exist....

A good string to search in Saint google ?

 :-*

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
In my case i think is simpler. I need only one parameter.
A good script for this ?

Loop, Read

FileAppend, % A_LoopReadLine, % SubStr("00" A_Index, -2) ".script.iim"

return

 :-[

kyrathaba

  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,200
    • View Profile
    • Donate to Member
Can you give me an example of two or three strings and then the contents of a CSV file and how you'd want to apply those contents toward extraction/replacement of substrings?

If you can give me some real world examples, I might be able to tackle this for you, OP.

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,832
    • View Profile
    • Donate to Member
In my case i think is simpler. I need only one parameter.

simpler than that...

this is (untested) in AHK...


inputbox, srch, Search String                      ; get a search string

inputbox, rep, Replacement string                  ;get a replacement string

fileselectfile, tmp_,,,Select a file, CSV(*.csv)   ; select a csv file

fileread, tmp_2, %tmp_%                            ; read in to a variable

stringreplace, %tmp_2%, tmp_2, %srch%, %rep%, all  ; replace all occurrences of the srch string with the rep string

fileappend, %tmp_2%, %tmp_%.csv                    ; write out to a new file

exitapp