Linux文档中的所有大写字符转换成小写字符

2025-10-23 20:50:06

1、举例如下,复制bash_profile 文件,命名为bash_profile.1,命令如下:

[lele@Oracle ~]$ cp .bash_profile bash_profile.1

Linux文档中的所有大写字符转换成小写字符

2、使用cat查看bash_profile.1,这里看到文件中有大写字符,如下:

[lele@Oracle ~]$ cat bash_profile.1

# .bash_profile

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

. ~/.bashrc

fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

Linux文档中的所有大写字符转换成小写字符

3、使用tr命令,将上面bash_profile.1文件中的所有大写字符转换成小写字符,这里需要输入bash_profile.1文档,使用输入重定向符号< 命令如下:

[lele@Oracle ~]$ tr 'A-Z' 'a-z' <bash_profile.1

# .bash_profile

# get the aliases and functions

if [ -f ~/.bashrc ]; then

. ~/.bashrc

fi

# user specific environment and startup programs

path=$path:$home/bin

export path

[lele@Oracle ~]$ 

Linux文档中的所有大写字符转换成小写字符

4、这里说明一下

[lele@Oracle ~]$ tr 'A-Z' 'a-z' <bash_profile.1

这里的tr 'A-Z' 'a-z' 就是说要把输入文档bash_profile.1文件中的所有大写字母A-Z全部转换成小写字符a-z,这里的小于符号<就是输入重定向符号,文件bash_profile.1就是需要输入的文件

可以看到最后的文件中,都是小写字母了

Linux文档中的所有大写字符转换成小写字符

5、tr命令,请参考我的百度经验 tr命令说明

Linux文档中的所有大写字符转换成小写字符

6、如果以上经验帮到您,麻烦在左下角给点个赞,谢谢!

Linux文档中的所有大写字符转换成小写字符

7、下面是man tr的所有文档

###########

SETs  are  specified  as  strings  of characters.  Most represent them-

       selves.  Interpreted sequences are:

       \NNN   character with octal value NNN (1 to 3 octal digits)

       \\     backslash

       \a     audible BEL

       \b     backspace

       \f     form feed

       \n     new line

       \r     return

       \t     horizontal tab

       \v     vertical tab

       CHAR1-CHAR2

              all characters from CHAR1 to CHAR2 in ascending order

       [CHAR*]

              in SET2, copies of CHAR until length of SET1

       [CHAR*REPEAT]

              REPEAT copies of CHAR, REPEAT octal if starting with 0

       [:alnum:]

              all letters and digits

       [:alpha:]

              all letters

       [:blank:]

              all horizontal whitespace

       [:cntrl:]

              all control characters

       [:digit:]

              all digits

       [:graph:]

              all printable characters, not including space

       [:lower:]

              all lower case letters

       [:print:]

              all printable characters, including space

       [:punct:]

              all punctuation characters

       [:space:]

              all horizontal or vertical whitespace

       [:upper:]

              all upper case letters

       [:xdigit:]

              all hexadecimal digits

       [=CHAR=]

              all characters which are equivalent to CHAR

###########

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢