Text processing tool

本文详细介绍了Linux系统中wc、cut、sort和uniq四个命令。wc用于统计文件的行数、单词数和字节数;cut可从文件每行中移除指定部分;sort能对文本文件的行进行排序;uniq用于报告或省略重复行。还给出了各命令的常用选项和示例,并布置了相关练习。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. wc : print newline, word, and byte counts for each file
    [root@bogon ~]# wc /etc/passwd
         44   88 2301 /etc/passwd
    -l: lines
    -w: words
    -c: characters
2. cut : remove sections from each line of files
    2.1 Commondly used options
        -d DELIMITER: specify the delimiter
        -f FILEDS:
            #: filed #
            #,#[,#]:Discrete(离散的) multiple filed,such as 1,3,6
            #-#:Consecutive(连续的) fields, such as 1-6
            a mixture use of -f :1-3,7
        --output-delimiter=STRING : specify the delimiter when print contents.
    2.2 example
        [root@bogon ~]# cut -d' ' -f 1 /etc/fstab
            The space key as the delimiter,print filed 1        
        [root@bogon ~]# cut -d: -f1 /etc/passwd
        [root@bogon ~]# cut -d: -f1-7 /etc/passwd
        [root@bogon ~]# cut -d: -f1-4 --output-delimiter='--' /etc/passwd   //specify output delimiter
3. sort : sort lines of text files
    3.1 Commondly used options
        -f: ignore case
        -r: sort in reverse
        -t DELIMITER: delimiter
        -k #:Sort by specified filed, and sort by ASCII by default
        -n: sort by numerical value
        -u: uniq,omit repeated lines after sorting
    3.2 example
        [root@bogon ~]# sort /etc/passwd
        [root@bogon ~]# sort -t: -k3 /etc/passwd
4. uniq : report or omit repeated lines
    4.1 repeat : continues and equal is repeat
    4.2 uniq can only omit repeated lines and cannot sort. sort -u omit repeated lines and sort at the same time.
    4.3 Commondly used options
        -c: print the number of repeated lines
        -d: Only print repeated lines
        -u: Only print lines that do not repeated.

5. exerciese :Seperated by colon,and take lines 6 to 10 of the /etc/passwd file and sort the information by numerical value of the third field , then only show the first field.
        
    

        


       

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值