Linux command-cut

Source: Internet
Author: User

A long time ago it was not very systematic to learn the common use of Linux commands for processing characters. Although the study progress at that time is also very satisfactory. But then it's easy to forget.

Now the system has learned the Linux shell command. Simply summarize:

Cut as the name implies, used to cut the target into a paragraph. Simply look at the usage.

Cut [-B |-C | -F] "number"-D "seprate"--complement--output-delimiter

-B split in bytes

-C is split in characters

-F is split in words.

To tell the truth,-b-c I really do not know how to distinguish, how to use also can not see the difference. At least the rule file, a self is a character ah.

These three options can be followed by a number, such as:

Cut-f 1 filename Indicates that only the first column is displayed

Cut-f. FileName shows 1 and 2 columns

Cut-f 1-4 filename indicates that 1 to 4 columns are displayed

-d Specifies the delimiter. The default is \ t. This is followed by a small example to illustrate, eat a loss, often remember prison.

--complement the collection. It's not hard to understand, is it?

--output-delimiter the output delimiter.


This is what is commonly used. The following combination of my one oolong to simple use cut.

I used vim to edit a rule file.

nonamemarkpercent1sarath45902alex49983anu4590
I thought the results would be exactly the same as expected. Results were beaten face.

Believe the reason at a glance, is nothing more than the problem of separators.

Why is there such a problem? When I typed it clearly, I used the tab.

That's starting with vim.

Vim has a command called set Expandtab. This may be specific to the programmer, the purpose is to expand the tab to a specified width of the space. So it looks like it's a tab, and it's actually replaced with a space.

What do we do?

Let's talk about how to check for tab segmentation.

1. If under VIM. Colon set list. You can see the type of the delimiter. The newline is $, and the tab is ^i. I have vim because there is no tab result is this.

2. If not in the VIM environment, do it, with cat-t. You can also view. The results are not posted.

How to solve it? There are many ways to do it.

1. Start with the VIM environment. Confirm that there is no tab after first: Set Noexpandtab. Then:%s/\+/\t/g

Just do it. Be careful not to replace the + with *. It's going to be a terrible death. Inside the regular expression, the + means at least one, while the * number means No.

2. The SED command is resolved. The regular is the same. Sed-i "s/\+/\t/g"

3. TR command resolution: To make a little detour. The TR command goes back in detail. First, take a look at its charm. Tr-s "" < filename | TR "" \ T "

Supplement: The TR function accepts data from the standard input. Its output is only available to standard output. If you want to use this command, don't forget to redirect at the end.

-S removes duplicates of the arguments that follow it, leaving only one. Then replace the space with \ t

Good drop, modify the later file using cat to look under:

OK. Look at the results of each scene.

Add a bit:-f-c-B number types that can be followed:

N,m Printing N and M

N-m Printing N to M

N-Start printing from n until the last

-M printing from the beginning until M


OK, just summarize so much. Interested students, can immediately knock knock, deepen the impression.

Linux command-cut

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.