Re: Sort across two or more files



On Thursday 30 October 2008 18:54, Quis custodiet ipsos custodes wrote:

OK, let's say we have three files: names, phone and age

[me@work /] cat names
Adam
Bob
Clare

[me@work /] cat phone
1234567
2345671
3456781

[me@work /] cat age
25
21
23

[me@work /] sort -n age
21
23
25

I now want to maintain the references between Names/Phone numbers/Ages
so that I don't end up just shuffling the data. (i.e. the Names file
gets changed to Bob-Clare-Adam, ditto the phone numbers file)

How do I accomplish this?

You might be ok with just

paste age names phone | sort -n -k1,1 | \
awk '{print $1>"age.new";print $2>"names.new";print $3>"phone.new"}

mv age.new age
mv names.new names
mv phone.new phone


.