In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This "how to use the cut command in Linux" article, the article sample code is introduced in great detail, with a certain reference value, interested friends must refer to, for "how to use the cut command in Linux", Xiaobian sorted out the following knowledge points, please follow the pace of the editor step by step slowly understand, then let us enter the topic.
The Linux common command cut command is used to display the specified part of the line and delete the specified field from the file. Cut is often used to display the contents of a file, similar to the type command
Cut connects the file and prints it to the standard output device
Additional note: the command has two functions, one is used to display the contents of the file, which in turn reads the files specified by the parameter file and outputs their contents to the standard output; the other is to connect two or more files, such as cut fl f2 > f3, the contents of the file fl and f2 will be merged together, and then through the output redirect ">" function, put them into the file f3.
When the file is large, the text flashes quickly on the screen (scrolling), and the user often cannot see what is displayed clearly. Therefore, it is generally displayed on different screens with commands such as more. To control scrolling, press Ctrl+S to stop scrolling; press Ctrl+Q to resume scrolling. Press the Ctrl+C key to terminate the execution of the command and return to the Shell prompt status.
Syntax cut (option) (parameter) option-b: displays only the contents of the specified direct range in the line;-c: displays only the characters in the specified range in the line;-d: specifies the delimiter of the specified field, and the default field delimiter is "TAB";-f: displays the contents of the specified field;-n: used with the "- b" option, does not split multibyte characters;-- complement: completes the selected bytes, characters, or fields -- out-delimiter= field delimiter: specifies the field delimiter that the output is;-- help: displays the help information of the instruction;-- version: displays the version information of the instruction. Parameter file: specifies the file to be filtered.
For example, there is a student report information that contains No, Name, Mark, and Percent:
[root@localhost text] # cat test.txt No Name Mark Percent 01 tom 69 91 02 jack 71 87 03 alex 68 98 use the-f option to extract the specified field (the f parameter here can be simply remembered as the abbreviation of-- fields):
[root@localhost text] # cut-f 1 test.txt No 01 02 03 [root@localhost text] # cut-f2Magol 3 test.txt Name Mark tom 69 jack 71 alex 68-complement option to extract columns other than the specified field (print columns except the second column):
[root@localhost text] # cut-f2-- complement test.txt No Mark Percent 01 69 91 02 71 87 03 68 98 use the-d option to specify the field delimiter:
[root@localhost text] # cat test2.txt No;Name;Mark;Percent 01TractX 69t91 02Traction71utter8703Tracterization68smart98 [root@localhost text] # cut-f2-d ";" test2.txt Name tom jack alex specifies the character or byte range of the field cut command can display a string of characters as a column, the notation of the character field:
N -: from the Nth byte, character, field to the end
Nmurm: from Nth byte, character, field to M (including M) byte, character, field
-M: from 1st byte, character, field to M (including M) byte, character, field.
The above is notation, and the bytes and characters of the range are specified as fields combined with the following options:
-b represents bytes
-c represents a character
-f represents a definition field.
Example
[root@localhost text] # cat test.txtabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz print the 1st to 3rd characters:
[root@localhost text] # cut-C1-3 test.txtabcabcabcabcabc print the first 2 characters:
[root@localhost text] # cut-Cmur2 test.txtababababab print from the fifth character to the end:
[root@localhost text] # cut-c5-test.txtefghijklmnopqrstuvwxyzefghijklmnopqrstuvwxyzefghijklmnopqrstuvwxyzefghijklmnopqrstuvwxyzefghijklmnopqrstuvwxyz what is a Linux system Linux is a free to use and freely spread UNIX-like operating system, is a POSIX-based multi-user, multi-tasking, multi-threading and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.
The above is all the contents of the article "how to use cut commands in Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.