Linux shell Script programming Note (iv): Seven ways to get the length of a string

Source: Internet
Author: User
Get seven Method 1 of string length. \${#str}

Length of 2.awk

Note:
1) It is best to use {} to place the variable
2) You can also use length ($) to count the lengths of each line in the file

3.awk NF

Note:-F is a delimiter, NF is the number of fields, that is, the length of a single string

4.WC-L

Note:-l parameter
1) for multi-line files, the length of the longest line is printed! 82, which indicates the length of the longest line of the/etc/passwd file is 82
2) for a single-line string, the length of the current line string!

5.wc-c

Note:
1)-C parameter: number of statistics characters
2)-N parameter: remove "\ n" line break, if not removed, by default with line break, the number of characters is 7

Length of 6.expr

7.expr $str: ". *" Tips

Note:. * represents any character, that is, to match a string with any characters, the result is matched to 6, that is, the length of the string is 6

From

http://blog.csdn.net/jerry_1126/article/details/51835119

Linux shell Script programming Note (iv): Seven ways to get the length of a string

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.