您的位置:首页 > 其它

文本处理命令1

2013-03-31 00:00 190 查看
shuf 随机显示几行

shuf -n <num> file

[buku@localhost ~]$ ps aux | shuf -n 10
root      1493  0.0  0.0      0     0 ?        S<   Mar28   0:00 [fcoethread/0]
root      2280  0.0  0.0   5568   304 ?        S    Mar28   0:00 udisks-daemon: not polling any devices
root      8248  0.0  0.0   2968  1068 ?        S<   Mar28   0:00 /sbin/udevd -d
buku      2290  0.0  0.5 179556  9444 ?        Sl   Mar28   0:01 gnome-volume-control-applet
buku      9951  0.0  0.0   5260  1532 pts/1    Ss   Mar28   0:00 bash
root      1967  0.0  0.0   2008   408 tty2     Ss+  Mar28   0:00 /sbin/mingetty /dev/tty2
root      1553  0.0  0.0   7308   360 ?        Ss   Mar28   0:00 /usr/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -B -u -f /var/log/wpa_supplicant.log -P /var/run/wpa_supplicant.pid
ntp       1839  0.0  0.0   5140  1132 ?        Ss   Mar28   0:00 ntpd -u ntp:ntp -p /var/run/ntpd.pid -g
68        1679  0.0  0.1   6812  2040 ?        Ss   Mar28   0:02 hald
buku      2324  0.0  0.7  67868 13764 ?        S    Mar28   0:09 /usr/libexec/clock-applet --oaf-activate-iid=OAFIID:GNOME_ClockApplet_Factory --oaf-ior-fd=28


split 分割文件

split -<行数> -b <字节> -C <字节> file <输出文件名>

[buku@localhost ~]$ ps aux | shuf -n 10 > netstat
[buku@localhost ~]$ split -4 netstat xx
[buku@localhost ~]$ ls xx*
xxaa  xxab  xxac
[buku@localhost ~]$ cat xxaa
gdm       2079  0.0  0.0   3628   404 ?        S    Mar28   0:00 /usr/bin/dbus-launch --exit-with-session
buku      9951  0.0  0.0   5260  1532 pts/1    Ss   Mar28   0:00 bash
root        31  0.0  0.0      0     0 ?        S    Mar28   0:00 [crypto/0]
buku      2202  0.0  0.0   3628   404 ?        S    Mar28   0:00 dbus-launch --sh-syntax --exit-with-session


csplit 还是分割文件

csplit file 1 2 3 file分成4分 0 1 2 3-10

[buku@localhost ~]$ csplit -f yy netstat 1 2 3
0
106
70
787
[buku@localhost ~]$ ls yy*
yy00  yy01  yy02  yy03


paste 列合并

[buku@localhost ~]$ cat <<EOF> file1
> 1
> 2
> 3
> EOF
[buku@localhost ~]$ cat file1
1
2
3
[buku@localhost ~]$ cat <<EOF> file2
> 4
> 5
> 6
> EOF
[buku@localhost ~]$ paste -d @ file1 file2
1@4
2@5
3@6


cut 列分割

[buku@localhost ~]$ paste -d @ file1 file2 > file3
[buku@localhost ~]$ cut -d '@' -f 2 file3
4
5
6
[buku@localhost ~]$ cut -d '@' -f 1 file3
1
2
3
-d 分割符 -f 显示第几段

uniq相同行只显示一行

[buku@localhost ~]$ cat file1
1
2
3
1
1
2
4
[buku@localhost ~]$ uniq file1
1
2
3
1
2
4


sort 排序

---------------------------------------------------------------------------------------------------------------------------------------
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: