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 usage of the Linux basic command uniq

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

Share

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

This article introduces the relevant knowledge of "the usage of the Linux basic command uniq". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Uniq

The repeated lines in the file are deleted and the results are sent to standard output or the specified file. Before using the uniq directive, you must use sort to sort the content, otherwise it has no effect. If there is no option, the matching rows are merged into the first match.

The scope of this command: RedHat, RHEL, Ubuntu, CentOS, SUSE, openSUSE, Fedora.

1. Grammar

Uniq [options] [input] [output]

2. List of options

Option

Description

-- version

Display command version information

-- help

Show help documentation

-c |-- count

Displays the number of times the row is repeated

-d |-- repeated

Show only recurring lines

-D |-- all-repeated [= delimit-method]

Print all duplicate lines

-f |-- skip-fields=N

Ignore the first n fields

-I |-- ignore-case

Ignore case when comparing

-s |-- skip-chars=N

Ignore the first n characters

-u |-- unique

Show only rows that do not repeat

-z |-- zero-terminated

Finishes with 0 bytes instead of newline

-w |-- check-chars=N

The comparison does not exceed the specified number of times

3. Examples

1) Delete duplicate lines

[root@192 weijie] # cat 3.c / / View content

Nihao linux.

I am david.

Nihao linux.

I am david.

[root@192 weijie] # sort 3.c | uniq-c / / sort first, and then delete duplicate rows, showing the number of duplicate rows

2 i am david.

2 nihao linux.

2) only rows that do not repeat are displayed

[root@localhost weijie] # cat 3.c / / View content

Nihao linux.

I am david.

Nihao linux.

I am david.

I love linux

[root@localhost weijie] # sort 3.c | uniq-c-u / / displays only lines that do not repeat

1 i love linux

This is the end of the introduction to "the usage of the Linux basic command uniq". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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