[shell基础]——uniq命令

uniq命令常见选项
      去除重复行
      -u  显示不重复的行
      -d  显示有重复的行
      -c  打印每一行重复的次数

测试文本内容如下:

# cat 4.txt
111
111
2222
2222
3333
3333
4444

(1)uniq
# cat 4.txt | uniq 去重复行
111
2222
3333
4444

(2) -u
# cat 4.txt | uniq -u 显示不重复的行
4444

(3) -d
# cat 4.txt | uniq -d 显示重复的行
111
2222
3333

(4) -c
# cat 4.txt | uniq -c 打印每一行重复的次数
2 111
2 2222
2 3333
1 4444

时间: 2024-08-04 18:37:31

[shell基础]——uniq命令的相关文章

shell基础--test命令的使用

test :用于文件类型检查和变量比较 一.用途: 1.判断表达式 2.判断字符串 3.判断整数 4.判断文件 测试例子: (1).test [[email protected]~_~ day5]# cat test.sh #!/bin/bash a=$1 b=$2 if test $a -eq $b then echo "a=b" else echo "a!=b" fi [[email protected]~_~ day5]# sh test.sh 1 1 a=b

[shell基础]——echo命令

echo命令:在shell中主要用于输出 1. -n     不换行的显示结果(默认是换行的) 2. -e " "  支持双引号中使用一些特殊字符 常用的特殊字符有 \a 发出警告声: \b 删除前一个字符: \c 最后不加上换行符号: \f.\v 换行但光标仍旧停留在原来的位置: \n 换行且光标移至行首: \r 光标移至行首,但不换行: \t 插入tab: \\ 插入\字符: \nnn 插入nnn(八进制)所代表的ASCII字符: 脚本实例 [[email protected] ~

[shell基础]——read命令

read命令:在shell中主要用于读取输入.变量.文本 1. 接受标准输入(键盘)的输入,并将输入的数据赋值给设置的变量      [按回车键——表示输入完毕]      [若输入的数据多于设置的变量数,则将多出的部分全部赋给最后一个变量]     [若没有设置变量,则将输入的数据赋给环境变量REPLAY] #!/bin/bash echo -n "Enter your name:" read name1 name2 echo hello,$name1,$name2 # ./read

[shell基础]——sed命令

关于sed sed 是一种在线编辑器,它一次处理一行内容.处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕.接着处理下一行,这样不断重复,直到文件末尾.文件内容并没有 改变,除非你使用重定向存储输出.sed主要用来自动编辑一个或多个文件:简化对文件的反复操作:编写转换程序等. sed详解 sed  [选项]  sed编辑命令  输入文件shell 命令 |  sed  [选项]   s

shell基础--cat命令的使用

一.cat的常用用法 1.总结 2.实验 (1).非交互式编辑 [[email protected]~_~ day5]# cat > cattest.sh <<STOP > hello > STOP [[email protected]~_~ day5]# cat cattest.sh hello [[email protected]~_~ day5]# cat > cattest.sh << EOF hello cat with EOF EOF [[ema

[shell基础]——sort命令

sort命令 sort是按照ASCII码升序输出,且是从首字符依次向后比较的 常见选项      -c 测试文件是否已经被排序 -r  逆向排序      -n 按照数字数值大小排序 -t  指定分割符      -k 指定域 -u 去除结果中的重复行      -m 合并两个已排序的文件      -o 将输出写到指定的文件 (1) -u 排序后去除重复行 # cat 1.txt 1:datadir=/aaa/zzz: 2:basedir=:cc 4:datadir=/sdfsfsd:dd 3

[shell基础]——cut命令

cut命令常见选项 测试文本内容如下: # cat name1.txt name1 alvin1 name2 alvin2 name3 alvin3 name4 alvin4 # cat 2.txt name1:100 name2:101 name3:102 (1) -c剪切每列的第1个字符# cat name1.txt | cut -c1nnnn 剪切每列的第1.3-4字符# cat name1.txt | cut -c1,3-4nmenmenmenme 剪切每列的前8个字符# cat nam

Linux Shell基础 read命令

read命令 read 命令用于接收标准输入(键盘)的输入,或者其他文件描述符的输入.得到输入后,read 命令将数据放入一个标准变量中,read 命令格式如下: [[email protected] ~]# read [选项] [变量名] 选项: -p "提示信息":在等待read输入时,输出提示信息: -t 秒数:read命令会一直等待用户输入,使用此选项可以指定等待时间: -n 字符数:read命令只接收指定的字符数就会执行: -s: 隐藏输入的数据,适用于机密信息的输入: 变量

[shell基础]——paste命令

测试文本内容如下: # cat name1.txt name1 alvin1 name2 alvin2 name3 alvin3 name4 alvin4 # cat name2.txt name1 100 name2 101 name3 102 cccccccccccccccc (1) paste 将两个文件的每行一一对应合并 # paste name1.txt name2.txt name1 alvin1 name1 100 name2 alvin2 name2 101 name3 alvi