Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The use of cut commands to extract text in Linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains the usage of using cut command to extract text in Linux. Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "the use of cut command to extract text in Linux".

Command usage:

Cut-b list [- n] [file...]

Cut-c list [file...]

Cut-f list [- d delim] [- s] [file...]

Parameters:

-b,-- bytes=LIST

Output these bytes

-c,-- characters=LIST

Output these characters

-d,-- delimiter=DELIM

Use DELIM instead of TAB as the field delimiter

-f,-- fields=LIST

Output these fields

-n

(ignore)

-s-- only-delimited

Lines without delimiters are not displayed

-- output-delimiter=STRING

Use STRING as the output delimiter and the default (output delimiter) as the input delimiter

-- help

Display help information and then end

-- version

Display version information, and then end

Use and use only one of-b,-c, or-f. A LIST consists of a range (range) or multiple ranges separated by commas. Scope is one of the following forms:

N

Nth byte, character, or field, counting from 1

N-

From the Nth byte, character or field to the end of the line

Nmurm

Bytes, characters, or fields from N to M (and including M)

-M

Bytes, characters, or fields from 1st to M (and including M)

If no file FILE is specified, or if FILE is -, the data is read from standard input.

Example:

The code is as follows:

[root@localhost ~] # cat / etc/passwd | cut-b 1 | first byte of head-5 # output file

R

B

D

A

L

The code is as follows:

[root@localhost ~] # cat / etc/passwd | cut-c 1-4 | the first four characters of the head-5 # output file

Root

Bin:

Daem

Adm:

Lp:x

The code is as follows:

[root@localhost ~] # cat / etc/passwd | cut-F1-d':'| head-5 # to split the file and output the first field

Root

Bin

Daemon

Adm

Lp

The code is as follows:

# cat a.txt

Ssss affff dddd fe fsc

Rrr f adfa eer ddd

The code is as follows:

# cat a.txt | cut-F1 Magazine 3-d $'\ t'# 1pare 3 columns

Ssss dddd

Rrr adfa

At this point, I believe you have a deeper understanding of "the use of cut commands to extract text in Linux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report