Shell编程日常积累_20160114

  • cat命令 显示文件
[root@ptadsv71g zsh]# cat fstab.s
test1:2016

test2:2017
[root@ptadsv71g zsh]# cat fstac.s
test1:2016

test2:2018

[root@ptadsv71g zsh]# cat *.s   #合并文件
test1:2016

test2:2017
test1:2016

test2:2018

[root@ptadsv71g zsh]# cat *.s | sort  #合并和排序文件



test1:2016
test1:2016
test2:2017
test2:2018
[root@ptadsv71g zsh]# cat *.s | sort | uniq  #合并和排序文件,留唯一行

test1:2016
test2:2017
test2:2018
[root@ptadsv71g zsh]# cat *.s | sort | uniq > test.txt  #合并和排序文件,留唯一行
[root@ptadsv71g zsh]# cat test.txt

test1:2016
test2:2017
test2:2018
[root@ptadsv71g zsh]# cat /dev/null > test.txt  #清除文件内容
[root@ptadsv71g zsh]# cat test.txt
[root@ptadsv71g zsh]#
  • tr 替换字符
[root@ptadsv71g zsh]# cat fstab.s
test1:2016

test2:2017
[root@ptadsv71g zsh]# tr 2 3 < fstab.s   #23
test1:3016

test3:3017
[root@ptadsv71g zsh]# tr 'a-z' 'A-Z' < fstab.s   #小写 ⇒ 大写
TEST1:2016

TEST2:2017
[root@ptadsv71g zsh]# tr 'a-z' 'A-Z' < fstab.s >test.txt  #小写 ⇒ 大写
[root@ptadsv71g zsh]# cat test.txt
TEST1:2016

TEST2:2017
[root@ptadsv71g zsh]#

未完待续

原文地址:https://www.cnblogs.com/SilverBullet/p/5130282.html