In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to use the cut command in linux. It is very detailed and has a certain reference value. Friends who are interested must finish it!
Description:
Cut splits the file by column, and you can specify a delimiter to separate each column. In cut terminology, each column is a field, which sometimes means the first column, which may be referred to as the first field.
Actual combat:
Suppose there is a file data.txt in the following format
NO Name Mark Percent
1 Sarath 45 90
2 Alex 49 98
3 Anu 45 90
The delimiter (delimiter) is a Tab tab character
If I want to get the second column, all the names, is there any good way? It's time for cut to show his skills.
1. Get 2 and 3 columns, namely name, and mark
$cut-f 2jue 3 data.txt
two。 Get all columns except column 3
$cut-f3-complement data.txt
3. With other delimiters, you can change it with-d.
The code is as follows:
Suppose data_comma.txt:
NO,Name,Mark,Percent
1,Sarath,45,90
2,Alex,49,98
3,Anu,45,90
Then:
$cut-f2-d "," data_comma.txt
Interpretation-help
Usage: cut [option]. [file].
Outputs the specified portion to standard output from each file.
The parameters that must be used for long options are also required for short options.
-b,-- the bytes= list selects only the specified bytes
-c,-- characters= list selects only the specified characters
The-d,-- delimiter= delimiter uses the specified delimiter instead of the tab as the zone delimiter
The-f,-- fields= list selects only those fields specified; and prints all fields that do not contain delimiters
OK, unless the-s option is specified
-n (ignore)
-- complement completes selected bytes, characters, or fields
-s,-- only-delimited does not print lines that do not contain delimiters
-- the output-delimiter= string uses the specified string as the output delimiter and defaults to input
Delimiter of
-- help displays this help and exits
-- version displays version information and exits
Use only one of f-b,-c, or-f. Each list is made specifically for a category, or you can separate it with a comma
Open different categories to display at the same time. Your input order will be used as the reading order, and each can be entered only once.
The scope of each parameter format is as follows:
The nth byte, character, or field starting from the first.
N-all characters, bytes, or fields from the nth to the end of the line
All characters, bytes, or fields from the Nth to the Mth (including the Mth)
-M all characters, bytes, or fields from the first to the M (including the M)
Read from standard input when there are no file parameters, or when the file does not exist
Interpretation:
1. To get a column of characters or bytes, you can use-c,-b, etc.
two。 You can get a range.
1 and 2 combined examples:
There is a file range_data.txt, which is as follows
Abcdefghijklmnopqrstuvwxyz
Abcdefghijklmnopqrstuvwxyz
Abcdefghijklmnopqrstuvwxyz
Abcdefghijklmnopqrstuvwxyz
Run: $cut range_data.txt-c Mel 2
Print character 1-2 columns
A little more complicated:
$cut range_data.txt-C1-3jue 6-9-output-delimiter ","
Print 1-3 lines, 6-9 lines, separated by commas.
The above is all the contents of the article "how to use cut commands in linux". Thank you for reading! Hope to share the content to help you, more related 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.