User Profile
Collapse
-
@bvdet: Excellent solution!!! Thank you very much!!! -
Python - Sort files based on timestamp encoded in the filename
I have a list which contains list of file names, i wanted to sort list of those files based on timestamp encoded in file names.
Note: In file, Hello_Hi_2015-02-20T084521_14245 43480.tar.gz --> 2015-02-20T084521 represents as "year-moth-dayTHHMMSS" ( Based on this i wanted to sort )
Input file below:
file_list = ['Hello_Hi_2015-02-20T084521_14245 43480.tar.gz',
'Hello_Hi_2015-02-20T095845_14245 43481.tar.gz',... -
@bvdet: Thank you for your help!!! This is working but still there is performance issue whenever input file size is more....
Could you please take a look into below code...
Code:def remove_Duplicate_Lines(inputfile, outputfile): with open(inputfile) as fin, open(outputfile, 'w') as out: lines = (line.rstrip() for line in fin) unique_lines = OrderedDict.fromkeys( (line for line in lines if line)
Leave a comment:
-
@bvet: You mean something like below:
Code:inputFile = open("in.txt", "r") outFile = open("out.txt", "w") log = [] for line in inputFile: if line in log and line[0:5] != "Jan 1": pass else: log.append(line) outFile.write("\n".join(log)) inputFile.close() outFile.close()
Leave a comment:
-
@bvdet: Thanks you very much!! I have already been tried this solution but here the problem is if the input message file size is more then it takes more time....
Below is the program which I have tried:
Code:inputFile = open("in.txt", "r") log = [] for line in inputFile: if line in log and line[0:5] != "Jan 1": pass else: log.append(line)
Last edited by bvdet; Jul 15 '15, 07:55 PM. Reason: Fix code tags. Tag [code] should be before code and closing tag [/code] after code.Leave a comment:
-
How to remove the duplicate lines retaining first occurences
Let's say a input text file "input_msg. txt" file ( file size is 70,000 kb ) contains following records..
Jan 1 02:32:40 hello welcome to python world
Jan 1 02:32:40 hello welcome to python world
Mar 31 23:31:55 learn python
Mar 31 23:31:55 learn python be smart
Mar 31 23:31:56 python is good scripting language
Jan 1 00:00:01 hello welcome to python world
Jan 1 00:00:02 hello welcome to python...Last edited by bvdet; Jul 15 '15, 04:56 PM. Reason: Please use code tags when posting code [code]......[/code] -
@bvdet: Thanks for the solution. Here i do not know the upper and lower value... How did you get those values...Leave a comment:
-
Extract Values between two strings in a text file using python
Lets say I have a Text file (input_file.txt , file size is ~10GB ).
Now I need to write a Python code which will read the text file and copy the contents between Start and end to another file.
I wrote the following code.
Code:import re with open(r'C:\Python27\log\master_input.txt', 'r') as infile, open(r'C:\Python27\log\output', 'w') as outfile: copy = False for
Last edited by bvdet; Jun 10 '15, 02:14 PM. Reason: Edited code tags. Place open tag "[code]" before code and closing tag "[/code]" after code.
No activity results to display
Show More
Leave a comment: