按bash排序文本文件的第一个字符串(直到'=') [英] Sort by bash a text file by the first string (till '=')

查看:45
本文介绍了按bash排序文本文件的第一个字符串(直到'=')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个缩写词的文本文件.每行以首字母缩写词(大写)开头,通常最多4个字母,然后是"=,然后是说明.例如

I have a text file for acronyms. Each line starts with the acronym (in uppercase), usually up to 4 letters, and then "=" and then the explanation. For example,

...

EST=Eastern Standard Time
OVS=Open vSwitch
IPMI=Intelligent Platform Management Interface 

...

IHV=Independent Hardware Vendor    
ISV=Independent Software Vendor

...

我想按照首字母缩写的升序对文本文件进行bash排序,首字母缩写是每行中的第一个字符串(直到"=").关于实现此目标的最佳方法有什么建议吗?

I want to sort this text file, in bash, by ascending order according to the acronym, which is the first string (till "=") in each line. Any suggestions as to the best way to achieve this ?

推荐答案

看看 sort 命令( man sort ).它具有用于定界键和建立排序参数的各种方式.

Take a look at the sort command (man sort). It has all manner of options for delimiting keys and establishing sorting parameters.

在您的简单情况下:

sort --field-separator="=" < sort.list

将主键设置为 = 之前的所有内容,并按升序对其进行排序.

would set the primary key to be everything up to the = and sort them in ascending order.

为此也有一个简短形式"(感谢@karafka!):

There is a "short form" for this, also (thanks @karafka!):

sort -t =

使用多个键和其他选项查看 man sort 有关排序顺序的详细信息.

Check out man sort for details on sort order, using multiple keys and other options.

这篇关于按bash排序文本文件的第一个字符串(直到'=')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆