0

I want to sort only rows in my file e.g

5 2
2 1

and I want to have an output like this

2 5
1 2

Could someone help me ?

MIKEZ0R
  • 1
  • 1
  • This question is not about Ubuntu at all. It is not really clear what you want.. which language do you work in? Do you want that output or do you want to rewrite the original file? – derHugo Nov 05 '17 at 15:10
  • text-processing is on-topic here, and we usually object when OP specifies a language, and solutions are normally given to stdout for this type of question @derHugo so I don't think any of your objections stand in this case. But the sample is very small, I would like a bigger one! – Zanna Nov 05 '17 at 17:12

1 Answers1

3

You could do it fairly simply with perl, if your fields are whitespace separated. Assuming you want to sort in numeric (rather than lexical) order:

$ perl -alne 'print join " ", sort {$a <=> $b} @F' file
2 5
1 2
steeldriver
  • 131,985
  • 21
  • 239
  • 326
  • @MIKEZ0R If you find this answer useful you [may "accept" it](https://askubuntu.com/help/someone-answers) by clicking on the tick mark (✓) next to it. – pomsky Nov 05 '17 at 16:59