Background
Let us sort by column position.
Data Files
Person.txt
john smith jsmith@nobody.com los angeles CA 90001 larry summers lsummers@treasury.gov new york-city NY 10001 twilla jacobs tjacobs@cincy.com cincinnati OH 45201 andy johnson ajohnson@yahoo.com miami FL 33101 tanya wilson twilson@gmail.com philadephia PA 19019
Image
Metadata
Column | Position |
---|---|
First Name | 1 |
Last Name | 2 |
Email Address | 3 |
City | 4 |
State | 5 |
Postal Code | 6 |
Display Text File
Cat Command
OS Platform – Win OS
Not Supported
OS Platform – Linux
Parameters
Parameter | Description |
---|---|
T | Show hidden characters |
Syntax
cat -T [file]
Sample
Sample – Cat with -T option
Command
cat -T /c/temp/person_delimited_tab.txt
Output – Image
Explanation
- Character :- ^I
- Indicates the tab character
Sort Data File By Column Number
Sort Command
OS Platform – Win OS
Not Supported
OS Platform – Linux
Parameters
Parameter | Description | Explanation |
---|---|---|
–debug | annotate the part of the line used to sort, and warn about questionable usage to stderr | |
-b | Ignore leading blanks | |
-k | Specify position | |
-t | Delimiter character | -t$’\t’ => Tab Character |
-h | human-numeric-sort | compare human readable numbers (e.g., 2K 1G) |
-n | Numeric Sort | compare according to string numerical value |
Syntax
sort -t [delimiter] -k [column-position] [file]
Sample
Sample – Sort By Email Address
Command
sort -t$'\t' -b -k 3 /c/temp/person_delimited_tab.txt
Image
Sample – Sort By City
Command
sort -t$'\t' -b -k 4 /c/temp/person_delimited_tab.txt
Image
Sample – Sort By Postal Code
Command
sort -t$'\t' -k 6 -n --debug /c/temp/person_delimited_tab.txt
Image
Explanation
- Sorted by postal Code
- -t
- $’\t’
- Delimited by tab
- -k
- column position
- Column position 6
- column position
- -n
- Numeric Data
- –debug
- Place an underline underneath the ordering column
- -t
Source Code
GitHub
Gist
file-person_delimited_tab-txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
john smith jsmith@nobody.com los angeles CA 90001 | |
larry summers lsummers@treasury.gov new york-city NY 10001 | |
twilla jacobs tjacobs@cincy.com cincinnati OH 45201 | |
andy johnson ajohnson@yahoo.com miami FL 33101 | |
tanya wilson twilson@gmail.com philadephia PA 19019 |
References
MS Windows
Reference
- Microsoft
- Microsoft | Docs
- Docs / Windows Server / Windows Commands / Reference
- Sort
Link
- Sort
- Docs / Windows Server / Windows Commands / Reference
- Microsoft | Docs
Linux
Reference
- man7.org
- Linux man-pages
- sort(1) — Linux manual page
Link
- sort(1) — Linux manual page
- Linux man-pages
Sample
- Stack Overflow
- Sorting data based on second column of a file
Link
- Sorting data based on second column of a file