好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > Linux命令 sort、uniq、tr工具詳解

Linux命令 sort、uniq、tr工具詳解

熱門標簽:蘭州語音電銷機器人軟件 電話機器人服務差 濟源電話外呼系統怎么樣 山東400電話如何辦理 智能外呼系統如何部署 高德地圖標注在建線路 宿州防封外呼系統廠家 電銷機器人對公司貢獻 ai電銷機器人 如何開發

Sort工具

Linux sort命令用于將文本文件內容加以排序。
sort可針對文本文件的內容,以行為單位來排序。

sort 常見選項

b 忽略每行前面開始出的空格字符。
-c 檢查文件是否已經按照順序排序。
-d 排序時,處理英文字母、數字及空格字符外,忽略其他的字符。
-f 排序時,將小寫字母視為大寫字母。
-i 排序時,除了040至176之間的ASCII字符外,忽略其他的字符。
-m 將幾個排序好的文件進行合并。
-M 將前面3個字母依照月份的縮寫進行排序。
-n 依照數值的大小排序。
-u 意味著是唯一的(unique),輸出的結果是去完重了的。
-o<輸出文件> 將排序后的結果存入指定的文件。
-r 以相反的順序來排序。
-t<分隔字符> 指定排序時所用的欄位分隔字符。
+<起始欄位>-<結束欄位> 以指定的欄位來排序,范圍由起始欄位到結束欄位的前一欄位。
–help 顯示幫助。
–version 顯示版本信息

sort工具示例

默認情況

默認情況下,sort工具會按字母順序進行排序

[root@1centos ~]# sort /etc/passwd
abrt:x:173:173::/etc/abrt:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin
chrony:x:992:987::/var/lib/chrony:/sbin/nologin
cockpit-ws:x:990:984:User for cockpit-ws:/:/sbin/nologin
colord:x:997:994:User for colord:/var/lib/colord:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
dirsrv:x:988:982:user for 389-ds-base:/usr/share/dirsrv:/sbin/nologin
dovecot:x:97:97:Dovecot IMAP server:/usr/libexec/dovecot:/sbin/nologin
dovenull:x:981:975:Dovecot's unauthorized user:/usr/libexec/dovecot:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin

將 /etc/passwd 以第三列進行反向排序

這邊就以數字倒敘進行排序了

[root@1centos ~]# sort -t: -rk 3 /etc/passwd
nobody:x:99:99:Nobody:/:/sbin/nologin
ods:x:999:999:softhsm private keys owner:/var/lib/softhsm:/sbin/nologin
polkitd:x:998:997:User for polkitd:/:/sbin/nologin
colord:x:997:994:User for colord:/var/lib/colord:/sbin/nologin
unbound:x:996:993:Unbound DNS resolver:/etc/unbound:/sbin/nologin
gluster:x:995:992:GlusterFS daemons:/run/gluster:/sbin/nologin
libstoragemgmt:x:994:991:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
saslauth:x:993:76:Saslauthd user:/run/saslauthd:/sbin/nologin
chrony:x:992:987::/var/lib/chrony:/sbin/nologin
geoclue:x:991:985:User for geoclue:/var/lib/geoclue:/sbin/nologin
cockpit-ws:x:990:984:User for cockpit-ws:/:/sbin/nologin
sssd:x:989:983:User for sssd:/:/sbin/nologin
dirsrv:x:988:982:user for 389-ds-base:/usr/share/dirsrv:/sbin/nologin
setroubleshoot:x:987:981::/var/lib/setroubleshoot:/sbin/nologin
saned:x:986:980:SANE scanner daemon user:/usr/share/sane:/sbin/nologin
gnome-initial-setup:x:985:979::/run/gnome-initial-setup/:/sbin/nologin
pcp:x:984:978:Performance Co-Pilot:/var/lib/pcp:/sbin/nologin
kdcproxy:x:983:977:IPA KDC Proxy User:/:/sbin/nologin
ipaapi:x:982:976:IPA Framework User:/:/sbin/nologin
dovenull:x:981:975:Dovecot's unauthorized user:/usr/libexec/dovecot:/sbin/nologin
dovecot:x:97:97:Dovecot IMAP server:/usr/libexec/dovecot:/sbin/nologin
hsqldb:x:96:96::/var/lib/hsqldb:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologi
……省略……

對 /etc/passwd 的第三列進行排序,輸出到 px.txt 中

[root@1centos ~]# sort -t: -k 3 /etc/passwd -o px.txt
[root@1centos ~]# cat px.txt 
root:x:0:0:root:/root:/bin/bash
xnftp:x:1007:1007::/home/xnftp:/sbin/nologin
vuser:x:1008:1008::/opt/vuser:/sbin/nologin
tom:x:1009:1009::/home/tom:/bin/bash
jerry:x:1010:1010::/home/jerry:/bin/bash
kongkong:x:1011:1011::/home/kongkong:/bin/bash
qemu:x:107:107:qemu user:/:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin

uniq工具

Linux uniq 命令用于檢查及刪除文本文件中重復出現的行列,一般與 sort 命令結合使用。

uniq常見選項

uniq 可檢查文本文件中重復出現的行列
-c或–count 在每列旁邊顯示該行重復出現的次數。
-d或–repeated 僅顯示重復出現的行列。
-f<欄位>或–skip-fields=<欄位> 忽略比較指定的欄位。
-s<字符位置>或–skip-chars=<字符位置> 忽略比較指定的字符。
-u或–unique 僅顯示出一次的行列。
-w<字符位置>或–check-chars=<字符位置> 指定要比較的字符。
–help 顯示幫助。
–version 顯示版本信息。
[輸入文件] 指定已排序好的文本文件。如果不指定此項,則從標準讀取數據;
[輸出文件] 指定輸出的文件。如果不指定此選項,則將內容顯示到標準輸出設備(顯示終端)

uniq工具示例

查看文件 the.txt

[root@1centos zhengzebiaodashi]# cat the.txt 
1the 2the 3the
1the 2the 3the
1the 2the 3the
1the 2the 3the

1the 2the 3the
2the 2the 3the
3the 2the 3the 4the 5the
4hello hi the word world
5 2 3 4 5 6 7 8

默認排序

[root@1centos zhengzebiaodashi]# uniq the.txt
1the 2the 3the

1the 2the 3the
2the 2the 3the
3the 2the 3the 4the 5the
4hello hi the word world
5 2 3 4 5 6 7 8

刪除重復行,并在顯示重復出現的次數

[root@1centos zhengzebiaodashi]# uniq -c the.txt 
   4 1the 2the 3the
   2 
   1 1the 2the 3the
   1 2the 2the 3the
   1 3the 2the 3the 4the 5the
   1 4hello hi the word world
   1 5 2 3 4 5 6 7 8

查找 testfile 文件中的重復行

[root@1centos zhengzebiaodashi]# uniq -d the.txt 
1the 2the 3the

tr工具

tr是translate的縮寫,是用來做翻譯或轉換工作的。具體來講,它可以對輸入內容(stdin)進行轉換或者刪除。是linux管道的必備工具。下面來看幾個常見的用法

tr常見選項

-c:取代所有不屬于第一字符集的字符;
-d:刪除所有屬于第一字符集的字符;
-s:把連續重復的字符以單獨一個字符表示;
-t:先刪除第一字符集較第二字符集多出的字符

tr工具示例配合 echo 將展示的小寫字母變大寫

[root@1centos zhengzebiaodashi]# echo "jb51" |tr 'a-z' 'A-Z'
JB51

替換輸出的重復字符

[root@1centos zhengzebiaodashi]# echo 'Thisssssss is cdsnnn' |tr -s 'sn'
This is cdsn

刪除字符串中的默寫字符

[root@1centos zhengzebiaodashi]# echo 'this is csdn' |tr -d 'th'
is is csdn

數組排序

有了這些工具,就可以簡單的給數組進行升序或者降序了

#!/bin/bash
read -p "請輸入你的數組,是空格隔開:" a
shuzu=($a)
echo "你的數組為:${shuzu[*]}"
echo "數組升序為:"
echo "$a" |tr ' ' '\n' |sort -n |tr '\n' ' '
echo ''
echo "數組降序為:"
echo "$a" |tr ' ' '\n' |sort -nr |tr '\n' ' '
echo " "

進行使用

[root@1centos zhengzebiaodashi]# source paixu.sh 
請輸入你的數組,是空格隔開:8 1 5 9 7
你的數組為:8 1 5 9 7
數組升序為:
1 5 7 8 9 
數組降序為:
9 8 7 5 1 

到此這篇關于Linux命令 sort、uniq、tr工具詳解的文章就介紹到這了,更多相關Linux命令 sort、uniq、tr工具內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持腳本之家!

標簽:安陽 巴中 云南 晉中 衡水 佛山 畢節 南寧

巨人網絡通訊聲明:本文標題《Linux命令 sort、uniq、tr工具詳解》,本文關鍵詞  Linux,命令,sort,uniq,工具,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Linux命令 sort、uniq、tr工具詳解》相關的同類信息!
  • 本頁收集關于Linux命令 sort、uniq、tr工具詳解的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 国产SUV精品一区二区欧K视频| 差差漫画免费漫画页面在线看漫画免费| 老师别我我受不了了| 美女裸体?开腿网站| 日本精油按摩做爰| 三级黄色片免费观看| 国产精品优女在线观看免费| 酒色激情网| 97人妻人人澡人人人爽人人sex | 在线观看资源| 十八女人国产毛毛片视频| 上司人妻迅雷下载| 免费高h视频| 都市美艳后宫下载全本下载| 一级做a爰片久久毛片人呢| 波多野结衣69| 99久久精品国产免看国产一区| 好湿?好紧?好多水含羞草| 小龙女级婬片A级艳片| 欧美性视频网| 99久久免费国产精品| 精品国产乱码久久久软件使用方法| 麻麻故意让我从屁股后面进去| 91人妻无码精品一区二区毛片| 很色的软件| 久青草国产在线视频97| 我的黑帮恋人电影在线观看| 日本电影和搜子同居的图片 | 嗯……啊啊| 日本久操| 特级毛片爽www免费版| 日本大尺度做爰无遮掩| 人禽交在线视频免费播放| 男人女人日批视频| 做爱动态图| 精品人妻一区二区三区日产| 娇妻趴撅着给人玩弄H| 仙子被强行双修巨大进入后面| 久久福利资源国产精品999| 搡老女人老妇老熟女50ⅩXXX| 女朋友韩剧完整版|