Basic Text processing-cut

Source: Internet
Author: User
Basic Text processing-the find, grep, sort, and uniq commands described above are all line text processing tools, however, we often want to know the content of a column in these rows or the content of only some columns is useful to us. what should we do in this case, how do I know... basic Text processing-the find, grep, sort, and uniq commands described above are all line text processing tools, however, we often want to know the content of a column in these rows or the content of only some columns is useful to us. what should we do in this case, how do I know the content of a specific column? The cut command is now available. Www.2cto.com 1. cut command cut bytes, characters, and fields from each line of the file and write these bytes, characters, and fields to the standard output. If the File parameter is not specified, the cut command reads the standard input. Cut command format: cut {-B List [-n] |-c List |-f List [-s] [-d Character]} [File...] parameter:-B List specifies the byte location. These byte locations ignore the multi-byte character boundary unless the-n flag is also specified. -C List specifies the character position. For example, if you specify-c 1-72, the cut command will write the first 72 characters in each line of the file. Www.2cto.com-d Character uses the Character specified by the Character variable as the field delimiter when the-f flag is specified. You must add quotation marks to characters that have special meanings to shell (such as space characters. -F List specifies the List of fields in the file that are separated by delimiters (tabs by default. For example, if you specify-f, the cut command only writes the first and seventh fields of each line. If the line does not contain field delimiters, the cut command does not perform any operations on them (useful for table subtitles) unless the-s flag is specified. -N unsplits multi-byte characters. It is used only with the-B flag. If the last byte of a character falls within the range indicated by the-B Mark List parameter, the character is written out; otherwise, the character is excluded. -S: cancels the line that does not contain delimiters. Only used with the-f flag. Note: The cut command must specify one of the-B,-c, or-f flag. The List parameter is a List of integers separated by commas, separated by spaces, or separated by hyphens (sequential increments ). A hyphen separator represents a range. The following entries are examples of the List parameter, which can be used to refer to bytes, characters, or fields, 71-3, 8-5,103-where-5 is a short form from the first to the fifth, and 3-is a short form from the third to the last. II. Example 1: # cat/etc/passwd | grep bashroot: x: 0: 0: root:/bin/bashbeckham: x: 500: 500: beckhamkuang: /home/beckham:/bin/bashking: x: 501: 501:/home/king:/bin/bashmysql: x: 100: 103: MySQL server: /var/lib/mysql:/bin/bash to split the first and 7th columns with: # cut-D': '-f/etc/passwd | grep bashroot: /bin/bashbeckham:/bin/bashking:/bin/bashmysql:/bin/bash2. Here, The-d parameter is used to specify the field delimiter ": "# tail-3/etc/passwd | cut-f-d ': 'Beckham:/home/beckhamking:/home/kingmysql: /var/lib/mysql 3. if you want to know what the home directory of every user is in the system, you can search for it in the/etc/password file, but all the contents are messy, we only need to find the desired content: # tail-3/etc/passwd | cut-f-D': 'Beckham:/home/beckhamking:/home/kingmysql: /var/lib/mysql

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.