How to traverse from a file to parse another file?

0 votes

I have a central location to store the logs, I have created a directory a  and in this place, I unzip all the logs:

After unzipping it created directory b and 123/567 under a

I am looking in the file /a/b/file1.txt

if there is an err-1 in /a/b/file1.txt

then I get the file name where the error occurred from file1.txt

/u01/prod/123/567/123_apply_2018Oct17_12_28_12.log  - shows directory structure on the sysytem where the error occured 

After unzipping the file in the directory a 123/567 sub directories are created directory and files will be stored in the location :

/a/123/567/123_apply_2018Oct17_12_28_12.log

From the python script how to I traverse from /a/b/file1.txt  to parse the file /a/123/567/123_apply_2018Oct17_12_28_12.log

Do I need to use subprocess in Linux and perform manually like this:

pwd 
/a/b
cd ..
cd 123/567 

How do i extract this from the string  /u01/prod/123/567/123_apply_2018Oct17_12_28_12.log and then parse the file 123_apply_2018Oct17_12_28_12.log?

I cannot do a string substitution because placeholder directory name may change, like it may be a1 or a2, a is variable but the directory structure after that is constant.

Jan 2 in Python by slayer
• 29,040 points
18 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

You use os.walk() module of python for traversing through directories and use regex to match directory names.

answered Jan 2 by Omkar
• 65,810 points

Related Questions In Python

0 votes
1 answer

How to Parse values from a JSON file?

import json from pprint import pprint with open('data.json') as ...READ MORE

answered Oct 15, 2018 in Python by Priyaj
• 56,100 points
32 views
0 votes
1 answer

how to read a JSON from a file?

You can use with statement with open('strings.json') as ...READ MORE

answered Oct 24, 2018 in Python by Priyaj
• 56,100 points
50 views
0 votes
1 answer

How to use read a WSDL file from the file system using Python suds?

Hi, good question. It is a very simple ...READ MORE

answered Jan 21 in Python by Nymeria
• 3,500 points
148 views
0 votes
1 answer

How to create and read from a temporary file in Python?

Hi, there is a very simple solution ...READ MORE

answered Jan 29 in Python by Nymeria
• 3,500 points
12 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 920 points
18 views
+4 votes
6 answers
0 votes
1 answer

How to print a message or the error if a file is not found?

To print the message that file is not ...READ MORE

answered Jan 2 in Python by Omkar
• 65,810 points
10 views
+1 vote
2 answers

Appending data to a file

First open the file that you want ...READ MORE

answered Jul 23, 2018 in Python by Omkar
• 65,810 points
20 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.