In my spare time I start to randomly check system commands ... that's why I often find interesting tips 🙂
This is one of them, precisely as the title indicates, I will show you how having a file with many lines of text inside, alphabetize the lines of that file.
For example, we have a file (called distros) containing the following:
linux
debian
ubuntu
archlinux
sabayon
gentoo
soluses
And we want to alphabetize these distros.
To do this in a terminal we put the following:
cat distros | sort > distros-ordenadas
And voila, I show you the screenshot of me executing this command, and then doing a cat (showing content) of the new file ordered-distros:
…. To what is extremely easy? 😀
The command Black you have many options, in the terminal if they do mansort it will show you all the options 😉
Anyway, a little tip that could solve several problems at a certain time hahahaha, I hope you liked it.
regards
This is very useful, thanks for sharing the information ~
Thanks to you for commenting 😉
Good tip 😉
Thank you
Where do you get the tips from?
Just as I said at the beginning of the post, in my spare time I start to review system commands 🙂
I found this one because I was looking for options or alternatives to the command locate, I tried searching for commands like "search" or something like that, but didn't find any, so I listed all the commands with s and after a while it caught my attention Black : )
Thanks for the comment, welcome to the blog 😀
Alternatives to "locate", you have the "whereis" and "find"
Yep, find I knew him ... but the whereis nop, hehe thanks 😀
I support Unix AIX and Sun servers (and from time to time a Red Hat or SuSe) entirely from the terminal and the truth is that the sort commands, along with cut, grep, awk, etc. they do wonders ^ ___ ^
Excellent, I have used it for a format of this model
100: user1
287: user2
150: user3
cat order.txt | sort -n> order1.txt
100: user1
150: user3
287: user2
Thank you…
Thanks, I was able to apply it correctly.
How do I get it to write it to the same file, that is, without having to assign it to a new file? Thank you!
If I don't misunderstand, for it to be modified in the same file is like redirecting the output to the file with the same name. BUT BEWARE! If you sent yourself a baton and you want to go back, you can't (the content is rewritten).
In the example they left us it would be:
cat distros | sort> distros
I don't know if the author of this post will see the comment, but I had a question with the «sort» command ...
In a file I put the list of directories that contained a certain file. Those directories have numbers in their name, so I use numbers like 100, 10, 1, .1 and .01
When you order them it makes everything ALMOST perfect:
1) It does not order from /.01, /.1, / 1, / 10 and / 100 (sorts like this:… / .01,… / 100,… / 10, but with internal alphabetical coherence of their respective subfolders)
2) Toggle one and one between… / .1 and… / 1
Can you think of how I can make the order look perfect or is it a limitation of the sort command?
Thank you in advance