Home » Support » Tutorials/Power Tips » UltraEdit for Linux » Advanced file sorting
IDM Power Tips

Sort files in UltraEdit for Linux

UEx includes a powerful sort engine with an abundance of features and fine-tuning capabilities, making UEx the ideal solution for nearly any situation requiring a text file sort on Linux. We will take a look at these options and work through the different parameters of the advanced sort in the following power tip.

Basic Sort

By default, UEx will sort your files alphabetically by evaluating the entire line, just like the Windows version. To execute a basic sort, where every line in the file is alphabetically arranged, go to File -> Sort -> Sort File.

UEx sort screenshot

In most cases, doing this is enough. But what if you want to sort on a particular field or value in each line and not the whole line itself? In these cases, you can use sort keys.

Using Sort Keys

As mentioned before, by default UEx will sort based on entire lines. To sort on keys instead, make sure you uncheck the Use Entire Line as Key in the Advanced Sort Options (you can access these from the File -> Sort submenu).

UEx sort screenshot

In the example shown in these screenshots, you can see that each separate "field" of data is delimited by a pipe character. We need to specify this in UEx's sort options. By default, sort will treat a whitespace character (tab or space) as a delimiter. To change this, expand the Options portion of the Advanced Sort Options dialog and check the Delimiter option. For our example we will enter the "|" character here. You may be working with CSV files in which case you could enter a comma as the delimiter. Any character used in your text file to delimit fields of data can be used here.

UEx sort screenshot

At this point in the tutorial, we must clarify an important difference between sorting in UltraEdit for Windows and sorting in UltraEdit on Linux:

UltraEdit for Windows defines keys based on column position. UltraEdit for Linux does not; instead it defines keys with fields which are separated by a delimiter (spaces/tabs by default).

We've specified the delimiter, but now we need to tell UEx which "field" to sort on. In the example shown in these screenshots, you can see data like the following:

Knight, Erin D.|02-83843679|42
Branch, Vladimir G.|02-31956584|20
Lambert, Lana J.|02-78267051|14
Koch, Ivan V.|01-51102587|37
Grant, Carly J.|02-52382695|26

Since we've specified the pipe character as the delimiter, sort will detect three fields on each line. You can think of it like this:

field 1|field 2|field 3

In this example, we want to sort on the second field; that is, the longer number which is preceded by either a "01-" or a "02-". But we want to ignore the leading "01-" or "02-" and ONLY sort on the number following this. With UEx sort keys and start/end fields and characters, this is easy enough.

First, we need to specify the field that UEx is going to sort on. Remember from our data above that the second field is the one we want to use for the sort. Therefore we will set our Start Field to 2 and our End Field to 2.

Now we need to tell UEx to sort beginning on the 4th character of the 2nd field, thereby ignoring the leading "01-" or "02-" Therefore we will set our Start Char to 4 and our End Char to 0. Using 4 tells UEx to begin evaluating the 4th character of the field, and using 0 tells UEx to sort to the end of the field.

UEx sort screenshot

Note: If you wished to sort on the ENTIRE field, you would use 1 and 0 as your Start Char and End Char, respectively.

Since we have no blanks and since case is not an issue when working with numerals, we can leave the Ignore Case and Ignore Blank options unchecked. We do, however, want to change the Sort Method from Dictionary to Numeric.

At this point, our custom sort key is complete and we can click Sort to sort the file.

Other Sort Options

In addition to using keys, there are some other very useful sort options in UEx. While this tutorial did not explicitly cover these other options, a brief description of each one follows.

File -> Sort All Files
This will sort all files that are currently open in UEx based upon the current sort settings in Advanced Sort Options.

File -> Sort and Merge All Files
This will merge all files that are currently open in UEx into a separate result file and then sort the merged result based upon the current sort settings in Advanced Sort Options.

The following options/settings are available within the File -> Sort -> Advanced Sort Options dialog.

Output to New File
This will write the sorted data to a new unsaved file, leaving the original file unaffected by the sort.

Merge Sort Results
This is only available if "All Open Documents" is selected in the Sort: drop down. This has the same effect as the File -> Sort and Merge All Files option described above.

Order
This allows you to specify the sort order. Dictionary is the default and will sort data alphabetically. These options are covered in further detail in the UEx help file.

Remove Duplicates
If this is checked, lines containing duplicate results (whether sorting on the entire line or by custom sort keys) will be removed from the file during the sort.

Reverse Order
If checked, the sort results will be reversed (bottom of file to top of file instead of top to bottom).

Ignore Leading Blanks
If checked, sort will ignore leading blanks. By default, a blank is a space or a tab, but the Locale drop down can change this.

Locale
Checking this allows you to choose a nonstandard locale in the drop down. This can affect the result of Dictionary, Month, Numeric, and Version sorts; and also has implications on Ignore Leading Blanks.

Ignore Case
If checked, lowercase letters will be treated the same as uppercase letters.

Stable Sort
If checked, this will stabilize sort by disabling its last-resort comparison so that lines in which all fields compare equal are left in their original relative order.

Delimiter
If checked, this allows you to specify a non-default delimiter for sort when specifying sort fields in the Keys options. By default, sort uses spaces and tabs as the delimiters that separate fields.


Back to power tips index


Download
Upgrade
Buy Now

Get your solution today!

UE/UC

Add UltraCompare to your purchase/upgrade of UltraEdit and complete your file management solution.

Your bundle license runs on Windows, Mac, and Linux.

Using a different distribution? No problem!

Get UltraEdit for Linux on any distribution with our universal .tar download...

IDM Highlights newsletter

Sign up now for...

  • Software Powertips
  • New Releases
  • Update Notices
  • Cool Tools, Specials
  • Company News