[Shell programming] File content case substitution

Source: Internet
Author: User

shell programming often encounters strings, file content-case conversions, and choosing the right commands in different scenarios can improve programming efficiency.

Applicable Scenarios

file contents or strings that need to be converted to uppercase and lowercase

string Case Substitution

lowercase Replace Uppercase

Echo " Hello World " TR ' [A-z] ' ' [A-z] ' Echo " Hello World " TR ' [: Lower:] ' ' [: Upper:] '

Uppercase Replace lowercase

Echo " Hello World " TR  ' [A-z] ' ' [A-z] ' Echo " HELLO World " TR  ' [: Upper:] ' ' [: Lower:] '

Uppercase and lowercase swaps

Echo " Hello World " TR ' [A-za-z] ' ' [A-za-z] '
file content case substitution < in situ replacement >

lowercase Replace Uppercase

sed ' s/[a-z]/\u&/g ' filename

Uppercase Replace lowercase

sed ' s/[a-z]/\u&/g ' filename

Replace the first letter of the word with uppercase

sed ' s/\b[a-z]/\u&/g ' filename
file content case substitution < required redirection >
TR 'A- z' 'A- z'< filename1 >filename2 #小写替换成大写TR 'A- z'  'A- z'< filename1 >filename2 #大写替换成小写awk '{print toupper ($)}'filename1 >filename2 #小写替换成大写awk '{print ToLower ($)}'filename1 > Filename2 #大写替换成小写

[Shell programming] File content case substitution

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.