Got it

Use the cut command in Linux to better split data

Latest reply: Dec 17, 2021 01:02:29 355 1 3 0 0

Hello, everyone!

This post I want to introduce you to cut command in Linux, let's learn it together.

What's a cut?

A Unix terminal command

Split the line content and output the standard output.

The data can be divided by byte, character, or separator.

What's the use?

Let's give a simple example (not all examples) to describe what a cut is and what it can do.

Simplified output, eliminating redundant interference information

For example, in this log, lines may be folded. In addition, assume that the information in the 04-19 18:26:55.605 22750 22883 W column is interference information.

Run the cut command to delete the redundant information.

Split by byte (cut -b)

Split by byte position

Split by byte interval

Split by byte position

By character

When we split by character, we encounter some problems, such as Chinese (one Chinese occupies three bytes).

However, if both Chinese and English exist, it is more troublesome. Fortunately, there is a method of splitting by character (cut -c).

Split by separator (cut -d)


  • The preceding example uses the echo and pipe method.

  • All of the above examples can be used in a form similar to the addition of files.

  • For example, cut -b 1 test_cut_file.txt,   cut -c 1 test_cut_file.txt,

    cut -d "|" -f 1 test_cut_file.txt.

That's all, thanks!

The post is synchronized to: Huawei Cloud Computing Case

  • x
  • convention:

Admin Created Dec 17, 2021 01:02:29

Thanks for your sharing!
View more
  • x
  • convention:


You need to log in to comment to the post Login | Register

Notice: To protect the legitimate rights and interests of you, the community, and third parties, do not release content that may bring legal risks to all parties, including but are not limited to the following:
  • Politically sensitive content
  • Content concerning pornography, gambling, and drug abuse
  • Content that may disclose or infringe upon others ' commercial secrets, intellectual properties, including trade marks, copyrights, and patents, and personal privacy
Do not share your account and password with others. All operations performed using your account will be regarded as your own actions and all consequences arising therefrom will be borne by you. For details, see " User Agreement."

My Followers

Login and enjoy all the member benefits


Are you sure to block this user?
Users on your blacklist cannot comment on your post,cannot mention you, cannot send you private messages.
Please bind your phone number to obtain invitation bonus.
Information Protection Guide
Thanks for using Huawei Enterprise Support Community! We will help you learn how we collect, use, store and share your personal information and the rights you have in accordance with Privacy Policy and User Agreement.