5-58 special symbol cut sort wc uniq tee tr split

Keywords: shell encoding Linux ascii

8.10 shell special symbol cut command

Special symbols

  • "*" stands for zero or more characters
  • "?" Represents a character
  • "#" Annotation Symbol
  • Symbol of \"De-meaning
  • "|" Pipeline Character

cut usage

[root@lixiang01 ~]# cat /etc/passwd |head -2
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
[root@lixiang01 ~]# cat /etc/passwd |head -2 |cut -d ":" -f 1,5
root:root
bin:bin
  • cut partition, used to display the specified part of a row
    • -d decision separator
    • -f wants that paragraph.
    • - c specifies the number of characters

8.11 sort_wc_uniq command

sort usage

Sort by Character Encoding Table

[root@lixiang01 ~]# head /etc/passwd > 1.txt
[root@lixiang01 ~]# vi 1.txt
[root@lixiang01 ~]# sort 1.txt
<
>
@#
2112
222
3421
432
adm:x:3:4:adm:/var/adm:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
{e33
]f
*%$#fs
halt:x:7:0:halt:/sbin:/sbin/halt
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
perator:x:11:0:operator:/root:/sbin/nologin
root:x:0:0:root:/root:/bin/bash
sfae
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
sjfoen
sync:x:5:0:sync:/sbin:/bin/sync

Numerically sorted by characters

[root@lixiang01 ~]# sort -n 1.txt
<
>
@#
adm:x:3:4:adm:/var/adm:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
{e33
]f
*%$#fs
halt:x:7:0:halt:/sbin:/sbin/halt
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
perator:x:11:0:operator:/root:/sbin/nologin
root:x:0:0:root:/root:/bin/bash
sfae
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
sjfoen
sync:x:5:0:sync:/sbin:/bin/sync
222
432
2112
3421

Inversion parameter: -r

[root@lixiang01 ~]# sort -n -r 1.txt
3421
2112
432
222
sync:x:5:0:sync:/sbin:/bin/sync
sjfoen
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
sfae
root:x:0:0:root:/root:/bin/bash
perator:x:11:0:operator:/root:/sbin/nologin
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
halt:x:7:0:halt:/sbin:/sbin/halt
*%$#fs
]f
{e33
daemon:x:2:2:daemon:/sbin:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
@#
>
<
  • Sort, sort the files, and output the sorting results (sorting by ASC II requires adjustment / etc/)
    • -n in numeric order
    • -r reverse order
    • -t separator
    • -kn1/-kn1,n2 Specified Segment Sorting

wc usage

[root@lixiang01 ~]# 
[root@lixiang01 ~]# Number of wc-m 1.txt characters
436 1.txt
[root@lixiang01 ~]# Wc-w 1.txt vocabulary (as long as no space is a word)
22 1.txt
[root@lixiang01 ~]# Number of rows wc-l 1.txt
22 1.txt


  • wc statistics, statistics and print line breaks, words, characters
    • - l Statistical Row Number
    • - m Statistical Character Number
    • -w statistical words

uniq usage

[root@lixiang01 ~]# vi 2.txt
[root@lixiang01 ~]# sort 2.txt |uniq -c
      3 1
      2 112
      2 123
      1 2
      2 33
      3 4
      2 5
      2 6
  • uniq weight removal,
    • -c Displays Repetition Number
    • Single use can only remove adjacent rows, often in conjunction with sort

8.12 tee_tr_split command

tee usage

[root@lixiang01 ~]# >a.txt
[root@lixiang01 ~]# cat a.txt
[root@lixiang01 ~]# sort 2.txt |uniq -c |tee a.txt
      3 1
      2 112
      2 123
      1 2
      2 33
      3 4
      2 5
      2 6
[root@lixiang01 ~]# cat a.txt
      3 1
      2 112
      2 123
      1 2
      2 33
      3 4
      2 5
      2 6
[root@lixiang01 ~]# sort 2.txt |uniq -c |tee -a a.txt
      3 1
      2 112
      2 123
      1 2
      2 33
      3 4
      2 5
      2 6
[root@lixiang01 ~]# cat a.txt
      3 1
      2 112
      2 123
      1 2
      2 33
      3 4
      2 5
      2 6
      3 1
      2 112
      2 123
      1 2
      2 33
      3 4
      2 5
      2 6
  • tee, similar to >, redirects are also displayed on the screen
    • -a Similar Augmentation Orientation

tr usage

[root@lixiang01 ~]# echo "axianglinux" |tr '[al]' '[AL]'
AxiAngLinux

  • TR replaces characters, tr'a''b', case replaces tr' [a-z]''[A-Z]'

split usage

[root@lixiang01 test]# find /etc/ -type f -name "*conf" -exec cat {} >> a.txt \;
[root@lixiang01 test]# split -b 10000 a.txt
[root@lixiang01 test]# ls
a.txt  xab  xad  xaf  xah  xaj  xal  xan  xap
xaa    xac  xae  xag  xai  xak  xam  xao  xaq
[root@lixiang01 test]# cat a.txt >> b.txt
[root@lixiang01 test]# cat a.txt >> b.txt
[root@lixiang01 test]# rm -f x*
[root@lixiang01 test]# rm -f a*
[root@lixiang01 test]# wc -l b.txt
8662 b.txt
[root@lixiang01 test]# split -l 1000 b.txt  
[root@lixiang01 test]# ls
b.txt  xaa  xab  xac  xad  xae  xaf  xag  xah  xai
[root@lixiang01 test]# wc -l *
  8662 b.txt
  1000 xaa
  1000 xab
  1000 xac
  1000 xad
  1000 xae
  1000 xaf
  1000 xag
  1000 xah
   662 xai
 17324 Total consumption
[root@lixiang01 test]# 

  • Split cutting, you can split a large file into many small files
    • - b size (default unit byte)
    • -l row number

8.13 Under shell special symbols

  • Variable prefix,!$combination, which means end of line
  • Multiple commands are written on one line, separated by semicolons, and can be executed one by one and output in sequence.
  • 65
  • Place the command behind it and leave it behind the scenes.
  • > > > > 2 > 2 > - > > // / Correct redirection Correct addition Error redirection Error addition Indiscriminate redirection
  • [] One of the specified characters, [0-9],[a-zA-Z],[abc]
  • | | and &&, between commands,

| | and & & Usage

It means you can't come, I'll come, & & It means you can come first, I'll go up.

[root@lixiang01 ~]# ls 1a.txt ; wc -l 2.txt
ls: Unable to access 1 a.txt: No file or directory
17 2.txt
[root@lixiang01 ~]# Ls 1a.txt | | wc-l 2.txt // / The previous command was unsuccessful, continue
ls: Unable to access 1 a.txt: No file or directory
17 2.txt
[root@lixiang01 ~]# Ls 1.txt | | wc-l 2.txt // / Stop if the previous command succeeds
1.txt
[root@lixiang01 ~]# Ls 1a.txt & & wc-l 2.txt// The previous command is unsuccessful, stop
ls: Unable to access 1 a.txt: No file or directory
[root@lixiang01 ~]# Ls 1.txt & & wc-l 2.txt// The previous command succeeded, continue
1.txt
17 2.txt

Related questions: http://ask.apelearn.com/question/5437

extend

  1. source exec distinguishes http://alsww.blog.51cto.com/2001924/1113112
  2. Linux Special Symbol Daquan http://ask.apelearn.com/question/7720
  3. sort is not sorted by ASCII at http://blog.csdn.net/zenghui08/article/details/7938975

Posted by alconebay on Thu, 20 Dec 2018 12:06:05 -0800