DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

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

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
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,840
    • Coding Snacks
more detail needed, eg what criteria would you use to determine whether to add or replace
Alcohol is photoshop, bottled
Askhole - someone who ask for advice, then ignores it
"Look wise, say nothing, and grunt. Speech was given to conceal thought" - Sir William Osler

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,649
    • Participated in NANY Challenge Eleven Times
    • Coding Snacks
    • Linux User
    • Hardware Hacker
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.
/Ton
Ath's software collection, Quote: "A problem well stated is a problem half-solved." (Charles Kettering)

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
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,947
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,947
I think a script of this must exist....

A good string to search in Saint google ?

:-*

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
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
    • Participated in NANY Challenge Eight Times
    • Programming School - Deluxe Bonus Medal
    • Programming School - Stage 1 Medal
    • Coding Snacks
    • Military Service Badge - US Army
    • Writer
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.
Win 10 Pro running on a 3.2 GHz CPU and 12 Gb RAM
__________________________________________

Proofreading Service: http://williammillerservices.com/proofreading

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,840
    • Coding Snacks
In my case i think is simpler. I need only one parameter.

simpler than that...

this is (untested) in AHK...

Code

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
Alcohol is photoshop, bottled
Askhole - someone who ask for advice, then ignores it
"Look wise, say nothing, and grunt. Speech was given to conceal thought" - Sir William Osler

Original address: https://www.donationcoder.com/forum/index.php?topic=40760.0