shell special symbols and cut, sort, wc, uniq, tr, split commands

Keywords: shell

shell special symbol

  • * Any character

  • ? Any character

  • # Annotation character

  • \ Definition character

  • Pipe symbol

  • Variable prefix,!$combination, which means end of line

  • Multiple commands are written on one line, separated by semicolons

  • ~ User's home directory, followed by regular expressions to represent matchers

  • & Put it behind the command and drop it behind the scenes.

  • > >> 2> 2>> &>

  • [] One of the specified characters, [0-9],[a-zA-Z],[abc]

  • || and & & between commands

cut_sort_wc_uniq command

cut separation

option

   -d separator

    - f Specifies a paragraph number

[root@localhost ~]# cat /etc/passwd |head -2 |cut -d ":" -f 1
root
bin
[root@localhost ~]# cat /etc/passwd |head -2 |cut -d ":" -f 1,2
root:x
bin:x
[root@localhost ~]# cat /etc/passwd |head -2 |cut -d ":" -f 1-3
root:x:0
bin:x:1

    - c Specifies the number of characters

[root@localhost ~]# cat /etc/passwd |head -2
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
[root@localhost ~]# cat /etc/passwd |head -2 |cut -c 4
t
:

sort sorting

Example:

option

    - n in numeric order: letters and special symbols marked 0

    -r reverse order

    - t separator - kn1/-kn1,n2

wc

option

    - l Statistical rows

[root@localhost a]# cat 1.txt |head -1
root:x:0:0:root:/root:/bin/bash
[root@localhost a]# cat 1.txt |head -1 |wc -l
1

    - m Statistical Character Number

[root@localhost a]# cat 1.txt |head -1 |wc -m
32
[root@localhost a]# cat 1.txt |head -1 |cat -A
root:x:0:0:root:/root:/bin/bash$

    - w statistic: using blank characters as separators

[root@localhost a]# echo 'aaa bbb,wwww 222211$a' |wc -w
3

uniq de-duplication

# uniq 1.txt) Need to be sorted before being duplicated
# sort 1.txt |uniq
[root@localhost a]# echo '2222
> 1111
> 2222
> 1111
> 1bx
> 2bx
> 1bx' |sort |uniq
1111
1bx
2222
2bx
# Uniq-c Statistical Row Number //sort 1.txt | uniq-c
[root@localhost a]# echo '222
111
222
1bx
2bx
1bx'|sort |uniq -c
      1 111
      2 1bx
      2 222
      1 2bx

tee_tr_split command

tee and > Similar, redirection is also displayed on the screen - a // append

root@localhost a]# echo '2222' |tee 2.txt
2222
[root@localhost a]# cat 2.txt
2222
[root@localhost a]# echo '2222' |tee -a 2.txt
2222
[root@localhost a]# cat 2.txt
2222
2222

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

[root@localhost a]# echo 'a' |tr 'a' 'A'
A

split cut, - b size (default unit byte), - l line number

[root@localhost a]# du -sh 1.txt
4.0K	1.txt
[root@localhost a]# split -b 100 1.txt
[root@localhost a]# ls
1.txt  xaa  xab  xac  xad  xae
[root@localhost a]# du -sh
24K	.
[root@localhost a]# ls -l
//Total dosage 24
-rw-r--r--. 1 root root 461 11 month 18 10:34 1.txt
-rw-r--r--. 1 root root 100 11 month 18 11:45 xaa
-rw-r--r--. 1 root root 100 11 month 18 11:45 xab
-rw-r--r--. 1 root root 100 11 month 18 11:45 xac
-rw-r--r--. 1 root root 100 11 month 18 11:45 xad


Posted by darga333 on Thu, 14 Feb 2019 08:12:19 -0800