Python Forum
Extracting data based on specific patterns in a text file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extracting data based on specific patterns in a text file
#1
I have a huge report file with some data where i have to do some data processing on lines starting with the code "MLT-TRR" For now i have extracted all the lines in my script that start with that code and placed them in a separate file. The new file looks like this.

MLT-TRR Warning C:\Users\Di\Pictures\SavedPictures\top.png 63 10 Port is not registered [Folder: 'Picture']

MLT-TRR Warning C:\Users\Di\Pictures\SavedPictures\tree.png 315 10 Port is not registered [Folder: 'Picture.first_inst']

MLT-TRR Warning C:\Users\Di\Pictures\SavedPictures\top.png 315 10 Port is not registered [Folder: 'Picture.second_inst']

MLT-TRR Warning C:\Users\Di\Pictures\SavedPictures\tree.png 317 10 Port is not registered [Folder: 'Picture.third_inst']

MLT-TRR Warning C:\Users\Di\Pictures\SavedPictures\top.png 317 10 Port is not registered [Folder: 'Picture.fourth_inst']

For each of these lines i have to extract the data that lies after "[Folder: 'Picture" If there is no data after "[Folder: 'Picture" as in the case of my first line, then skip that line and move on to the next line. I also want to extract the file names for each of those lines- top.txt, tree.txt

I couldnt think of a simpler method to do this as this involves a loop and gets messier. Is there any way out i can do this? extracting just the file paths and the ending data of each line.
Reply


Messages In This Thread
Extracting data based on specific patterns in a text file - by K11 - Aug-28-2020, 04:09 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Copy Paste excel files based on the first letters of the file name Viento 2 478 Feb-07-2024, 12:24 PM
Last Post: Viento
  Extracting specific file from an archive tester_V 4 559 Jan-29-2024, 06:41 PM
Last Post: tester_V
  data validation with specific regular expression shaheen07 0 363 Jan-12-2024, 07:56 AM
Last Post: shaheen07
  Color a table cell based on specific text Creepy 11 2,110 Jul-27-2023, 02:48 PM
Last Post: deanhystad
  Regex Include and Exclude patterns in Same Expression starzar 2 824 May-23-2023, 09:12 AM
Last Post: Gribouillis
  Grouping Data based on 30% bracket purnima1 4 1,237 Mar-10-2023, 07:38 PM
Last Post: deanhystad
  The included URLconf 'scribimus.urls' does not appear to have any patterns in it. nengkya 0 1,084 Mar-03-2023, 08:29 PM
Last Post: nengkya
  Split pdf in pypdf based upon file regex standenman 1 2,138 Feb-03-2023, 12:01 PM
Last Post: SpongeB0B
  Extracting Data into Columns using pdfplumber arvin 17 5,710 Dec-17-2022, 11:59 AM
Last Post: arvin
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,157 Dec-15-2022, 04:32 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020