unix 命令 - 忽略“The"排序时 [英] unix command - ignore "The" while sorting

查看:23
本文介绍了unix 命令 - 忽略“The"排序时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在列出目录,我想按名称排序,但忽略前导The",即输出应为:

I am listing directories and I would like to sort by name, but ignore leading "The", ie the output should be:

Apple
The Banana
Orange

而不是

Apple
Orange
The Banana

最好的方法是什么?

推荐答案

ls | sed -e 's/^The \(.*\)/\1, The/' | sort | sed -e 's/\(.*\), The$/The \1/'

这篇关于unix 命令 - 忽略“The"排序时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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