当前位置:网站首页>Shell script - sort, uniq, TR, array sort, cut, Eval command configuration
Shell script - sort, uniq, TR, array sort, cut, Eval command configuration
2022-07-28 06:57:00 【Fish fire loach】
shell Script ——sort、uniq、tr、 Array sorting 、cut、eval Command configuration
One 、sort command
Sort the contents of the file in behavioral units , It can also be sorted according to different data types
1、 Grammar format
sort [ Options ] Parameters
cat file | sort Options
2、 Common options

3、 Command configuration and examples
sort -n testfile2
sort -t ‘:’ -k 3 -n /etc/passwd
du -a | sort -nr -0 du.txt

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-mHomdKBa-1658074073763)(https://s2.loli.net/2022/07/18/EkQ92HS3egGvjbW.png)]
Two 、uniq command
Used to report or ignore consecutive duplicate lines in the file , Often with sort Command in combination with
1、 Grammar format
uniq [ Options ] Parameters
cat file | uniq Options
2、 Common options
3、 Command configuration and examples
uniq testfile3
sort -n testfile3 | uniq -c
3、 ... and 、tr command
Commonly used to replace characters from standard input 、 Compress and delete
1、 Grammar format
tr [ Options ] [ Parameters ]
2、 Common options

3、 Parameters
Character set 1
Specifies the original character set to convert or delete . When performing a transformation operation , Parameters must be used “ Character set 2” Specifies the target character set of the transformation . But when you delete , No parameters required “ Character set 2”;
Character set 2
Specifies the target character set to convert to
4、 Command configuration and examples
echo “abc” | tr ‘a-z’ ‘A-Z’
echo -e “abc\ncabcdab” | tr -c “ab\n” “0”
echo -e “abc\ncabcdab” | tr -c “ab” “0”
echo ‘hello world’ | tr -d ‘od’
echo “thissss is a text linnnnnnne.” | tr -s ‘sn’
Delete blank lines
echo -e “aa\n\n\n\n\nbb” | tr -s “\n”
cat testfile5 | tr -s “\n”
Put the colon in the path variable ":“, Replace with a newline ”\n"
echo $PATH | tr -s “:” “\n”
echo -e “aa\n\n\n\n\nbb” | tr -s "\n” “:”
Delete Windows file “ cause ” Of "^M’ character :
cat abc.txt | tr -s “\r” “\n” > new_ file
or
cat abc.txt | tr -d “\r” > new_file
Linux Line break encountered in (“\n”) Will enter + Line feed operation , Instead, the carriage return character will only be used as a control character (“^M”) Show , No carriage return occurs . and windows in Want a carriage return
+ A newline (“\r\n”) Will enter + Line break , Missing a control character or out of order cannot start another line correctly .
cat -v abc.txt
dos2unix abc.txt
Four 、 Array sorting
echo ${array[*]} | tr ’ ’ ‘\n’ | sort -n > file
a=0
for i in ( c a t f i l e ) d o a r r a y [ (cat file) do array[ (catfile)doarray[a]=KaTeX parse error: Expected 'EOF', got '#' at position 11: i let a++ #̲array+=(i)
done

5、 ... and 、cut command
Display the specified part in the row , Delete the specified field in the file
1、 Grammar format
cut Options Parameters
cat file | cut Options
2、 Common options

3、 Command configuration and examples
cut -d ‘:’ -f 1 /etc/passwd
grep ‘/bin/bash’ /etc/passwd|cut -d ‘:’ -f 1-4,6,7
# With - Separated start and end fields specify the range of fields
grep ‘/bin/bash’ /etc/passwd|cut -d ‘:’ --complement -f 2
# Exclude the second field
cut -d ‘:’ -f1,7 --output-delimiter=’ ’ /etc/passwd
# The output separator is separated by spaces
i=123456789
echo $i| cut -b 1-3 # Starting from 1 Start
123
echo ${i:0:3} # Starting from 0 Start
expr substr $i 1 3 # Starting from 1 Start 
6、 ... and 、eval command
with eval when ,shell Will scan it twice before executing the command .eval The command will first scan the command line for all permutations , Then execute the command . This command is applicable to those variables that cannot perform their functions in one scan . This command scans variables twice

、eval command
with eval when ,shell Will scan it twice before executing the command .eval The command will first scan the command line for all permutations , Then execute the command . This command is applicable to those variables that cannot perform their functions in one scan . This command scans variables twice
[ Outside the chain picture transfer in …(img-oOSVIXFn-1658074073766)]

边栏推荐
- JS四则运算重新封装,解决精度丢失问题
- Technology sharing | sending requests using curl
- Scratch command
- Network - network layer
- Archery database audit platform deployment
- Ubuntu18.04+centos7 configure redis master-slave [learning notes]
- JS reverse question 100 - question 1
- 如何描述一个BUG以及BUG级别的定义、生命周期
- Ubuntu18.04+Centos7配置redis主从【学习笔记】
- Ubuntu18.04搭建redis集群【学习笔记】
猜你喜欢

Which brand of air conduction earphones is good and highly praised
![[explain in detail how to realize Sanzi chess step by step]](/img/17/68ef51ec2be0c86019461116ecaa82.png)
[explain in detail how to realize Sanzi chess step by step]

MySQL主主

Applet navigator cannot jump (debug)

技术分享 | 使用postman发送请求

Build php7 private warehouse

技术分享 | 实战详解接口测试请求方式Get、post

iptables防火墙

shell脚本——编程条件语句(条件测试、if语句、case分支语句、echo用法、for循环、while循环)

shell脚本——“三剑客”之awk命令
随机推荐
思寒漫谈测试人职业发展
ISO 3.0-server three power separation configuration
技术分享 | 接口自动化测试中,如何做断言验证?
C language memcpy library functions and the role of memmove
搭建PHP7私有仓库
技术分享 | 使用postman发送请求
Technology sharing | detailed explanation of actual combat interface test request methods get, post
What is the good brand of air conduction Bluetooth headset and the best brand recommendation of air conduction headset
技术分享 | 如何模拟真实使用场景?mock 技术来帮你
Technology sharing | sending requests using curl
Repair the faulty sector
手把手教你三步完成测试监控系统搭建
Difference between process and thread
On cookies and session
小tips
Detailed explanation of LNMP construction process
Array to linked list
MySQL common commands
修复故障扇区
防火墙——iptables防火墙(四表五链、防火墙配置方法、匹配规则详解)
