sed one-liner 将所有大写字母转换为小写字母? [英] sed one-liner to convert all uppercase to lowercase?

查看:50
本文介绍了sed one-liner 将所有大写字母转换为小写字母?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本文件,其中一些单词全部大写.我希望能够使用 sed 将文本文件中的所有内容都转换为小写.这意味着第一句话会读到,我有一个文本文件,其中一些单词全部大写."

I have a textfile in which some words are printed in ALL CAPS. I want to be able to just convert everything in the textfile to lowercase, using sed. That means that the first sentence would then read, 'i have a textfile in which some words are printed in all caps.'

推荐答案

With tr:

# Converts upper to lower case 
$ tr '[:upper:]' '[:lower:]' < input.txt > output.txt

# Converts lower to upper case
$ tr '[:lower:]' '[:upper:]' < input.txt > output.txt

或者,GNU 上的 sed(但不支持 BSD 或 Mac,因为它们不支持 \L\U):

Or, sed on GNU (but not BSD or Mac as they don't support \L or \U):

# Converts upper to lower case
$ sed -e 's/\(.*\)/\L\1/' input.txt > output.txt

# Converts lower to upper case
$ sed -e 's/\(.*\)/\U\1/' input.txt > output.txt
 

这篇关于sed one-liner 将所有大写字母转换为小写字母?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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