如何使用sed在大写和小写之间传输字符 [英] How to transfer characters between uppercase and lowercase with sed

查看:31
本文介绍了如何使用sed在大写和小写之间传输字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我的 src.tex 是

For example, my src.tex is

SectionType *p = NULL;

我想把它改成

section_type *p = NULL;

我想要做的只是改变SectionType,但保持NULL不变,我使用了y/[AZ]/[az],但这将改变所有行.

what I want to do is just change the SectionType, but remains the NULL unchanged, I used y/[A-Z]/[a-z], but this will change all the line.

我的 sed 不支持 \L,\l,\U 和 \u 函数,它的版本是 3.* 并且在 FSF 下分发,而不是 GNU,可能是 GNU 可以很好地处理这些函数,但当时我可以不采用 GNU 的,因为我在 msys 中工作并且没有 GNU 包.

My sed do not support \L,\l,\U and \u functions, it version is 3.* and distributed under FSF, not GNU, may be GNU's works well with this functions, but at the time I could not adopt the GNU's because I'm working in msys and there is no GNU package.

有什么解决办法吗?

推荐答案

来自 这里

将 CamelCase 或 camelCase 转换为 camel_case:

Convert CamelCase or camelCase to camel_case:

sed -e 's/\([AZ][az]\)/_\l\1/g' -e 's/^_\([az]\)/\1/g' 文件.txt

输入:

SectionType *p = NULL;
sectionType *p = NULL;
ABCSectionType *p = NULL;

输出:

section_type *p = NULL;
section_type *p = NULL;
ABC_section_type *p = NULL;

这篇关于如何使用sed在大写和小写之间传输字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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