Python Forum
Parsing file and get a specific text
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Parsing file and get a specific text
#1
Hi everyone,

I'm new in scripting with python (in general too). I need some help to get a block text in a file.

This is my code :
stop = "end"
last_line = 0
searchtxtDetected = False
with open("20181107-115829-192.168.220.201.txt", 'r') as file:
	for txt in file:
		if 'show running-config' in txt:
			searchtxtDetected = True
			continue
		if searchtxtDetected:
			print (txt)
			#last_line += 1
			if txt == stop:
				break
Nevertheless, the code start when show running-config is parse but dont stop when it match my variable and print the entire file end !

The file to check my code
https://ufile.io/4eiaa
Reply


Messages In This Thread
Parsing file and get a specific text - by dds69 - Nov-09-2018, 10:28 AM
RE: Parsing file and get a specific text - by dds69 - Nov-12-2018, 08:06 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Text parsing Arik 5 453 Mar-11-2024, 03:30 PM
Last Post: Gribouillis
  Extracting specific file from an archive tester_V 4 554 Jan-29-2024, 06:41 PM
Last Post: tester_V
  Color a table cell based on specific text Creepy 11 2,094 Jul-27-2023, 02:48 PM
Last Post: deanhystad
Video doing data treatment on a file import-parsing a variable EmBeck87 15 2,981 Apr-17-2023, 06:54 PM
Last Post: EmBeck87
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,154 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Reading Specific Rows In a CSV File finndude 3 1,014 Dec-13-2022, 03:19 PM
Last Post: finndude
  How to extract specific data from .SRC (note pad file) Shinny_Shin 2 1,293 Jul-27-2022, 12:31 PM
Last Post: Larz60+
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,730 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  Parsing xml file deletes whitespaces. How to avoid it? Paqqno 0 1,059 Apr-01-2022, 10:20 PM
Last Post: Paqqno
  Extracting Specific Lines from text file based on content. jokerfmj 8 3,101 Mar-28-2022, 03:38 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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