Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

batch file to alter txt files through multiple find and replace


  • Please log in to reply
3 replies to this topic

#1 josefmiller

josefmiller

  • Members
  • 3 posts
  • OFFLINE
  •  
  • Local time:11:19 PM

Posted 10 March 2018 - 07:37 PM

HI all,

 

I'm working on analysing data in txt format.
Data are in about 22000 files, in one main directory under many sub and sub sub-directories.
Each file has a different number of data records.
Each data record starts with the word "Type" and consists of a number of segments separated by "%" (percent character).

In order to run data analysis, I need to change the format of every data file so that:
1. first find and replace % with regex \r\n (a newline or carriage return), so that the segments will be in successive order, and
2. then find and replace the word Type with a new line above it, i.e. with \r\nType, so that each record is separated with one empty line from the record above.

I usually do this manually for a handful number of files, but when it comes to thousands of them I become in need for an expert hand to help. So can I get some precious assistance with this request, please?

Many thanks in advance.

J.



BC AdBot (Login to Remove)

 


#2 britechguy

britechguy

    Been there, done that, got the T-shirt


  • Moderator
  • 9,327 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Staunton, VA
  • Local time:06:19 AM

Posted 10 March 2018 - 08:12 PM

To be perfectly honest I don't exactly see why you would remove one delimiter '%' only to replace it with another delimiter.

 

That being said, I suggest you take a look at:  

 

                              https://www.dostips.com/DtTipsStringOperations.php


Edited by britechguy, 10 March 2018 - 08:12 PM.

Brian  AKA  Bri the Tech Guy (website in my user profile) - Windows 10 Home, 64-Bit, Version 1809, Build 17763 

     Presenting the willfully ignorant with facts is the very definition of casting pearls before swine.

             ~ Brian Vogel

 

 

 

              

 


#3 josefmiller

josefmiller
  • Topic Starter

  • Members
  • 3 posts
  • OFFLINE
  •  
  • Local time:11:19 PM

Posted 10 March 2018 - 09:23 PM

Thanks for your comment. Coding wise, % is not a delimeter in the data text file, it is just a separator between data segments (fields). Data analysis necessitates that all data segments should be in a successive list form, and all data records are separated with one empty line between. Doing so, I can run data analysis perfectly.



#4 josefmiller

josefmiller
  • Topic Starter

  • Members
  • 3 posts
  • OFFLINE
  •  
  • Local time:11:19 PM

Posted 11 March 2018 - 09:59 AM

I found this powerful "find and replace utility" at this link: http://findandreplace.io/ through which I fulfilled my need. 

 

This topic may be marked as resolved at this point.

 

J.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users