Merging all file_name.log's files from directory to one and search “PerformanceINFO" - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Merging all file_name.log's files from directory to one and search “PerformanceINFO" (/thread-31410.html) |
Merging all file_name.log's files from directory to one and search “PerformanceINFO" - sutra - Dec-09-2020 My question is: Following question, I want to achieve it in python although I have done this in bash(i have added my code at the end) but I want that to happen in python Step1: I have a bunch of Quote:.logfiles in the directory Quote:Directory : /home/vs/vs_work2/Chi_DEPB/ & merge them into one file Quote:merged_file.txt Quote:Now merged_file.txt looks like as follows Step2: Now, from that Quote:merged_file.txtlook for PerformanceINFO and extract 6 lines every time they appear and put it in Quote:Extracted.txt Quote:Extracted.txt file looks like Step3: From Quote:Extracted.txtfile look for Quote:payload_sizes (bytes) & packet_datarate (bits/clk)and merge them every time they appear and put them into Quote:output_file.csv Quote:Output_file.csv looks like My bash code which to be converted to python Step1: Quote:cat /home/vs/vs_work2/Chi_DEPB/*.log > merged_file.txt Step2: Quote:grep -A9 -P '^PerformanceINFO *$' merged_file.txt >> Extracted.txt Step3: Quote:awk -F: '/packet_datarate/ { packt=packt""gensub(/[ {}]/,"","g",$2) } /payload_sizes/ { payl=payl""gensub(/[ {}]/,"","g",$2) } END { print "payload_sizes(bytes):,"payl;print "packet_datarate(bits/clk):,"packt }' Extracted.txt >> Output_file.csv |