how to use Linux command Sort to sort the text file according to 4th column, numeric order?
Tag : linux , By : judith
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I have a file like this(which is space delimited): sort -nk4 file
-n for numerical sort
-k for providing key
sort -nrk4 file
|
merge and sort two sorted text file
Date : March 29 2020, 07:55 AM
I hope this helps . Try this: few fixes: k,h.append instead of k,h= otherwise k and h are list and k[][] is a char instead of a string one = open("sample-r1.txt",'r')
two = open("sample-r2.txt",'r')
k=[]
h=[]
for line in one:
tmp=line.rstrip().split('\t')
if len(tmp)>1:
k.append ( tmp )
for record in two:
tmp=record.rstrip().split('\t')
if len(tmp)>1:
h.append ( tmp )
i=0
j=0
newList=[]
while i < len(k) and j < len(h):
if k[i][1] <= h[j][1]:
newList.append(k[i])
i+=1
else:
newList.append(h[j])
j+=1
while i < len(k):
newList.append(k[i])
i+=1
while j < len(h):
newList.append(h[j])
j+=1
for row in newList:
print("\t".join(row))
|
Combine multiple unsorted text files into one sorted file using python
Tag : python , By : Tim Coffman
Date : March 29 2020, 07:55 AM
it should still fix some issue I have a list of text files names as a variable in python. I want to create another text file which contains all the lines of the files in the list, and I want this file to be sorted by lines. , I created simple files with 3 lines each. My solution is: with open("file 1.txt", 'r') as f1, open("file 2.txt", 'r') as f2,open("file 3.txt", 'r') as f3:
with open("outfile.txt", 'w') as o:
files = [f1,'b',f2,'b',f3]
for i in files:
if i != 'b':
lines = i.readlines()
else:
lines = '\n'
o.writelines(lines)
file 1 line 1
file 1 line 2
file 1 line 3file 2 line 1
file 2 line 2
file 2 line 3file 3 line 1
file 3 line 2
file 3 line 3
f = open("outfile.txt",'r')
print(f.read())
file 1 line 1
file 1 line 2
file 1 line 3
file 2 line 1
file 2 line 2
file 2 line 3
file 3 line 1
file 3 line 2
file 3 line 3
|
Sort input text file and output file in ascending order (perl)
Tag : perl , By : Mossy Breen
Date : March 29 2020, 07:55 AM
|
Find integer in text file rewrite in new text file as string Python
Date : March 29 2020, 07:55 AM
|