Windows Command Line sort Tutorial

Windows Command Line sort Primer Tutorial

Windows Command Line sort Tutorial

If you were to nominate the most frequent “chore” you set your “software programs” to do, and we should never forget we are here to make software that achieves something, there is a big chance you’d choose the job of sorting data. The why I guess relates to how a lot of we humans want data presented … we seek order … and are generally a bit afraid of chaos … whether this is good always is for 56784533 other conversations to have.

Let’s go back to a thinking close to the operating system of interest … and today that is Windows (remember when we covered Linux sort Tutorial as shown below?) … specifically its command line, and only its command line … in the old days called DOS or (MS-DOS) … we set ourselves the task not to compile anything … just straight DOS batch … and look at some command line Windows Command Line that will work on most/all Windows operating systems … it is pretty fundamental stuff, and we use the same CSV input data file as for the tutorial below so that you can compare and contrast.

The base command of interest may amaze you … are you ready …


sort [inputFile]

… gasp … but sort just like that (without switches) assumes …

  1. alphabetical sorting (okay as switch in Linux sort but not in DOS sort, as a switch)
  2. total record sorting (in DOS sort can have a character position to start at as a switch, but this seldom suits CSV sorting) (as if all the characters on a carriage return/line feed delimited string)
  3. ascending sort (from least to greatest) (in DOS there is a “/r” switch (for reverse sort) available)
  4. the sort determination looks from the leftmost character and proceeds to the right

… but, today, with our piped sort commands we present switches that can work with the first three defaults, respectively, the first two of which we have to tailor some DOS Batch programming code …

  • /n (we invent for our job)
  • we will assume a comma as a delimiter and allow user to specify a (single) field number to sort on
  • /r (as said above, exists in DOS sort command now, and we will allow its usage … doh!)

… in other words …

  • numerical sort
  • sort by field [colNumber] where fields are separated by comma
  • descending sort

So doing this proved pretty ugly when you don’t involve any compiled code … and we came up with …

Link to the supervising csvsort.bat with the usage instructions …

@rem csvsort.bat
@rem RJM Programming – January, 2015
@rem Defaults to three comma separated fields to sort and default csv3.bat and vsc3.bat as written
@rem Usage: csvsort[.bat] [[numFields] [rowsToSkip]] inputCSVFilename [fieldNumberOfSort] [/n] [/r]
@rem Defaults: /n does numerical sort and /r reverses the sort
@rem Defaults: rowsToSkip=0 fieldNumberOfSort=1 (starting at 1) numFields=3 (if specified please also specify a rowsToSkip value)

Link to the supervised (and only suitable for 3 column record CSV files … if feeling strong, write others for your own purpose) … csv3.bat and vsc3.bat and the more generic lpad10.bat


Previous relevant and contrasting Linux sort Tutorial is shown below.

Linux sort Primer Tutorial

Linux sort Tutorial

If you were to nominate the most frequent “chore” you set your “software programs” to do, and we should never forget we are here to make software that achieves something, there is a big chance you’d choose the job of sorting data. The why I guess relates to how a lot of we humans want data presented … we seek order … and are generally a bit afraid of chaos … whether this is good always is for 56784532 other conversations to have.

Let’s go back to a thinking close to the operating system of interest … and today that is Linux … and look at some command line Linux that will work on most/all Linux or Unix operating systems … it is pretty fundamental stuff.

The base command of interest may amaze you … are you ready …


sort [inputFile]

… gasp … but sort just like that assumes some of the defaults (depending on your deep configuration settings (ie. in your profile, with an alias, you can change them)) …

  • alphabetical sorting
  • total record sorting (as if all the characters on a carriage return/line feed delimited string)
  • ascending sort (from least to greatest)
  • the sort determination looks from the leftmost character and proceeds to the right

… but, today, with our piped sort commands we present switches that can change the first three defaults, respectively …

  • -n
  • -k [colNumber] -t[delimiterCharacter]
  • -r

… in other words …

  • numerical sort
  • sort by field [colNumber] where fields are separated by [delimiterCharacter]
  • descending sort

We also touch on other commands with our look at Linux sorting of our input CSV data that we talked about with PHP/Javascript/HTML Google Chart JSON Data Table Import of CSV Tutorial as shown below that has fields “Country”,”Population”,”Crude Birth Rate” …

  • cat [CSVfileName] … type a file called [CSVfileName]
  • uniq … pipe to enforce record uniqueness
  • sort -u … pipe and switch to enforce field (of record) uniqueness
  • grep ‘[searchCriteria]’ … piped filter to include only records satisfying [searchCriteria]
  • sed ‘/$/s//,5/g’ … piped record modifier adding a new column (ie. ,5) to right of our input CSV data

Hope you find some interest in this Linux operating system command discussion. This is raw command line talk but it can also be supervised as a useful component tool by, (amongst other ideas by) …

  • web server side language supervision … eg. via PHP exec for example, or via curl (of that PHP)
  • called by compiled desktop program, such as Java, C++, C
  • called by a Linux/Unix shell script … in Bourne Shell, Korn Shell, C Shell, tcsh, Unix Shell

Previous relevant data from PHP/Javascript/HTML Google Chart JSON Data Table Import of CSV Tutorial is shown below.

PHP/Javascript/HTML Google Chart JSON Data Table Import of CSV Tutorial

PHP/Javascript/HTML Google Chart JSON Data Table Import of CSV Tutorial

Here is a tutorial that introduces you to Google Graphs API, or Google Chart Tools, and its JSON Data Table functionality.

Google Chart Tools provide a perfect way to visualize data on your website. From simple line charts to complex hierarchical tree maps, the chart galley provides a large number of well-designed chart types. Populating your data is easy using the provided client- and server-side tools.

Thanks to the World Bank for some statistics which helped a lot.

Let’s see some PHP code in live action for this tutorial where you see a JSON Data Table derived from a filename passed as a parameter in the URL. The data shown is based on a CSV file of a previous PHP/Javascript/HTML Google Chart Intensity Map Tutorial shown below.

Link to Google Chart Tools “spiritual home” … via Google.
Link to Google Chart Tools JSON Data Table information … via Google.

Link to some downloadable PHP programming code … rename to chart_editor_in.php.
Link to some downloadable PHP programming code … rename to json_data_table.php.
Link to some downloadable input CSV data … rename to Google_Chart_Intensity_Chart_Tutorial_as.CSV.


Previous PHP/Javascript/HTML Google Chart Intensity Map Tutorial below …

PHP/Javascript/HTML Google Chart Intensity Map Tutorial

PHP/Javascript/HTML Google Chart Intensity Map Tutorial

Here is a tutorial that introduces you to Google Graphs API, or Google Chart Tools, and its Intensity Map functionality.

Google Chart Tools provide a perfect way to visualize data on your website. From simple line charts to complex hierarchical tree maps, the chart galley provides a large number of well-designed chart types. Populating your data is easy using the provided client- and server-side tools.

Thanks to the World Bank for some statistics which helped a lot.

Let’s see some PHP code in live action for this tutorial where you define your intensity map characteristics and data.

Now part of an Android App called Geo Chart++ in July 2013.

Link to Google Chart Tools “spiritual home” … via Google.
Link to Google Chart Tools Intensity Map information … via Google.

Link to some downloadable PHP programming code … rename to intensity_chart.php.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Operating System, Tutorials and tagged , , , , , , . Bookmark the permalink.

15 Responses to Windows Command Line sort Tutorial

  1. Louis says:

    Hello, ciekawy rozdziaΕ‚. Pewien czas nie sΕ‚uchaΕ‚em tak ciekawego pisarstwa.

  2. I agree, this site is truly useful as well as we got a suggestion of this certain topic. I never thought that I could possibly discover this web site. I would like to use this in my life. Many thanks for this and also hope you will create even more such as this one.

  3. I truly wanted to make a quick comment to express gratitude to you for some of the nice tips and hints you are giving on this site. My incredibly long internet search has at the end been paid with awesome tips to go over with my friends and family. I would claim that we site visitors actually are unequivocally blessed to live in a very good place with many wonderful professionals with interesting principles. I feel extremely blessed to have discovered your website and look forward to so many more fabulous moments reading here. Thanks once again for everything.

  4. What i do not realize is in truth how you are no longer really much more neatly-appreciated than you might be now. You’re very intelligent. You understand therefore significantly when it comes to this matter, produced me for my part believe it from so many various angles. Its like women and men aren’t fascinated unless it‘¦s one thing to accomplish with Girl gaga! Your individual stuffs excellent. All the time maintain it up!

  5. Opportunity says:

    Thank you for every other informative blog. Where else may I get that type of information written in such an ideal manner? I’ve a venture that I’m just now operating on, and I’ve been on the look out for such info.

  6. Car Styling says:

    I as well as my friends were digesting the great techniques from your web page and then before long got an awful feeling I never expressed respect to the site owner for those strategies. All the women are actually certainly joyful to learn them and already have extremely been loving those things. Thanks for really being really thoughtful and then for using such extraordinary resources most people are really desperate to be informed on. My very own honest regret for not expressing gratitude to you sooner.

  7. You made some nice points there. I did a search on the subject and found mainly folks will consent with your blog.

  8. example says:

    Thank you a lot for sharing this with all folks you really recognize what you are speaking approximately! Bookmarked. Kindly also consult with my web site =). We will have a hyperlink alternate agreement between us!

  9. Best says:

    My web surfing seem complete.. thank you. So content to have found this publish.. of course, investigation is paying off. I enjoy you sharing your perspective..

  10. deserve says:

    Thank you a lot for sharing this with all folks you really know what you are talking approximately! Bookmarked. Please additionally consult with my web site =). We may have a hyperlink change contract among us!

  11. sell says:

    I value you writing your point of view.. Treasure the blog you supplied.. Liking the document.. pleased Mighty good viewpoint, thank you for writing..

  12. Courtnay says:

    Unquestionably imagine that that you said. Your favourite reason seemed to be on the internet the simplest factor to have in mind of. I say to you, I certainly get annoyed at the same time as other folks think about worries that they just do not understand about. You controlled to hit the nail upon the highest and also defined out the whole thing without having side effect , other people could take a signal. Will likely be again to get more. Thanks|

  13. Appreciating the persistence you put into your webpage and comprehensive information and facts you offer. It is fantastic to encounter a weblog just about every once in a while that isn’t exactly the same old rehashed material. Excellent read! I’ve bookmarked your site and I am adding your RSS feeds to my Google account.

  14. Normally I don’t learn article on blogs, however I wish to say that this write-up very pressured me to check out and do so! Your writing taste has been amazed me. Thanks, very great post.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>