How to sort lines of files on Linux by just the first character

If you need to order a file just by the first character then you can use this command:

$ sort -k1.1,1.1 filename

It will show the result in the standard output, then append “> newfile” to above command to create a new file with sorted lines.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s