![]() But the man page has an option for this: -f, -ignore-case Looks good, how about doing it in reverse: sort -r letters.txtĪlso easy, but what if we want to be case insensitive? Hang on a sec, according to the output it’s already case insensitive. We’ll do the most basic sort first: sort letters.txt To start with we have the following file: cat letters.txt It helps to have examples to truly grok the kinds of stuff you can do with sort, so let’s have a look. We can look at the man page for sort and discover all sorts of interesting bits, but even the man page is not really clear on the more advanced aspects of sort usage. As much is we like hacking things together, if a tool can already do all the work for us, we want to know about it. Well I hope that we’re somewhat more curious than your average developer :). Which is fair enough, you rarely need to dig deeper, the default behaviour will usually do what you need and when it doesn’t – we have Ruby or Perl, we can hack something together. The extent of most people’s knowledge ends with: sort some_file.txt Whether you’re answering an interview question about sorting or simply need to quickly sort some data in you day to day work – the Linux sort command is your friend. However, often enough you just don’t need to draw on this deeper knowledge. ![]() Sorting is a fundamental task when it comes to programming, if you have a decent knowledge of various sorting algorithms, their advantages and disadvantages, you will be a better software developer for it. ![]() Note: I am using bash, so your mileage might vary if you’re using a different shell. I will cover grep and find ( as well as other valuable commands) in subsequent posts – here we will concentrate on sort. So, if you really put in the effort to master them, not only will you make your own life much easier, but you will also be able to impress all you friends with your elite Linux skills when you pair with them :). Just about everyone has at least a passing familiarity with these commands, but with most people the knowledge is superficial, they don’t even realise how powerful those commands can be. There are a number of these with the main ones being grep, find and sort. If you do your development work in Linux, there are certain commands that you owe it to yourself to master fully. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |