I need to sort a file by the first column, if there is a numerical entry, and by the second column when there is none in the first. It looks basically like this:
3 - foo bar
1 1 foo bar
- 5 foo bar
2 2 foo bar
- 4 foo bar
and I need the output then to be
1 1 foo bar
2 2 foo bar
3 - foo bar
- 4 foo bar
- 5 foo bar
Is there any nice way to do that in linux with a single command? Thanks!
在遵循该格式的输出上,您可以只使用基本的sort命令:
sort -k 1,2 foo.txt
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.