SED / AWK利用串 [英] sed/awk capitalize strings

查看:117
本文介绍了SED / AWK利用串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三种类型,我想在bash脚本大写的字符串。我想通SED / AWK将是我最好的选择,但我不知道。什么是给出了以下要求的最佳方式是什么?

I have three types of strings that I'd like to capitalize in a bash script. I figured sed/awk would be my best bet, but I'm not sure. What's the best way given the following requirements?

1)一个字
     例如塔科 - >塔克

2)多个单词用连字符隔开
     例如我的鱼,玉米饼 - >我-鱼炸玉米饼

2.) multiple words separated by hyphens e.g. my-fish-tacos -> My-Fish-Tacos

3)多个单词用下划线分隔
     例如 my_fish_tacos - > My_Fish_Tacos

3.) multiple words separated by underscores e.g. my_fish_tacos -> My_Fish_Tacos

推荐答案

有没有必要使用捕获组(虽然&安培; 是一个的方式):

There's no need to use capture groups (although & is a one in a way):

echo "taco my-fish-tacos my_fish_tacos" | sed 's/[^ _-]*/\u&/g'

输出:

Taco My-Fish-Tacos My_Fish_Tacos

越狱的小写字母U大写的匹配的子字符串中的一个字符。

The escaped lower case "u" capitalizes the next character in the matched sub-string.

这篇关于SED / AWK利用串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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