Reputation: 121
My file contains a number of lines all of which contain a tab delimited sequence of terms. I would like to sort these tab delimited terms alphabetically within each line using the 'sort' command but seem to be unable to do it.
Thanks for your help
Markus
Upvotes: 0
Views: 25
Reputation: 20025
You could use awk to sort the fields of each row:
awk '{split($0,a);asort(a);for(i=1;i<=NF;i++)$i=a[i];print}' a.txt
Upvotes: 1
Reputation: 8154
per_row = []
infile = open('Myfile.txt', 'r')
for line in infile:
per_row.append(line.split('\t'))
sorted = [x for x in sorted(infile)]
print (sorted)
above is a python code to sort the file
Upvotes: 0