How I can extract specific target number from text file

saratoon J.

Input from text file

mpls switch-l2vc 10.123.150.98 205131102 tunnel-policy TE between 10.123.130.1 
mpls switch-l2vc 10.123.150.100 213131302 tunnel-policy TE between 10.123.130.1 
mpls switch-l2vc 10.123.149.52 205129302 tunnel-policy TE between 10.123.130.1 
mpls switch-l2vc 10.123.149.50 205129102 tunnel-policy TE between 10.123.130.1
mpls switch-l2vc 10.123.159.38 212134501 tunnel-policy TE between 10.123.130.1 
mpls switch-l2vc 10.123.150.99 205131202 tunnel-policy TE between 10.123.130.1 
mpls switch-l2vc 10.123.150.99 205131212 tunnel-policy TE between 10.123.130.1 

Expect out out ## --(keep only start "205")

mpls switch-l2vc 10.123.150.98 205131102 tunnel-policy TE between 10.123.130.1 
mpls switch-l2vc 10.123.149.52 205129302 tunnel-policy TE between 10.123.130.1 
mpls switch-l2vc 10.123.149.50 205129102 tunnel-policy TE between 10.123.130.1
mpls switch-l2vc 10.123.150.99 205131202 tunnel-policy TE between 10.123.130.1 
mpls switch-l2vc 10.123.150.99 205131212 tunnel-policy TE between 10.123.130.1

From expect output : I prefer select that row contain number is "205" in the fourth boundary text in row.

Tim Biegeleisen

We could try a regex approach using re.search:

with open('input.txt') as f:
    lines = f.readlines()

for line in lines:
    if re.search(r'^\S+ \S+ \S+ 205\d+.*$', line, re.M):
        print(line)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I extract specific strings from a text file and add to List?

How can I extract a specific number from a filename

How can I extract number from text with regular expression

How can I extract these characters from a text file?

How can I extract data from text file?

How can I extract a text from a bytes file using python

How can I extract a portion of text from all lines of a file?

How to extract specific number of bits from a hexadecimal number for a given text file

How to extract a specific text from gz file?

How can I both extract a specific line in a text file as well as multiple lines containing a specific string?

How i can Read text file from a specific line in python?

How can I delete a specific text from a file

How can I extract the number from this BeautifulSoup?

How extract extract specific text from pdf file - python

How can I extract text from images?

How can I write a regex to extract data preceding and following a specific expression in a text file?

How to extract a specific text from text file in c#

REGEX - how to extract a specific number of rows from a text

How can I use phpoffice to extract a specific worksheet from an .xlsx file and create a new .xlsx from it?

How do I extract specific words from a string in a text file? c++

How can I extract a number of rows from a very big file from a known position?

How do I extract a number from a text file and perform modular arithmetic?

How can I extract a 6 digit number from the text in excel? Examples shown below

Can I use Powershell to automatically extract an unknown string with a specific pattern from a XML file and write that string in a text file?

How can I extract text between parentheses containing a specific word?

How can I look into a cell with VBA to find specific text, then extract it?

How can I extract a specific text in an html code with Selenium and Python

R: How can I count the number of times specific words appear in a text file in R?

Using Perl, how can I extract from a log file only the errors that happened during a specific minute?

TOP Ranking

HotTag

Archive