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)
attention
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!