撷取


cut -d '
分隔符号'-f fields

root@timfeng-desktop:~#echo$PATH
/usr/lib/jvm/jdk1.7.0_09/bin:/usr/share/ant/bin:/root/Downloads/android-sdk-linux/platform-tools:/usr/bin:/bin:

root@timfeng-desktop:~#echo $PATH | cut -d ':' -f 1
/usr/lib/jvm/jdk1.7.0_09/bin

root@timfeng-desktop:~#echo $PATH | cut -d ':' -f 1,5
/usr/lib/jvm/jdk1.7.0_09/bin:/bin



-c以字符串单位截取固定区间的字符

root@timfeng-desktop:~# export|cut -c 1-5
decla
decla
decla

grep

刚刚的cut是就将一行讯息当中,取出我们想要的,而grep则是分析一行讯息,若当中有我们所需要的信息,就将改行拿出来

grep [-acinv] [--color=auto]'搜寻字符串'filename
root@timfeng-desktop:/etc#last|grep --color=auto 'root'    <==
查询含有root的数据
root    pts/0        :0.0            Tue Feb  5 15:20   still logged in

sort [-fbMntuK] [file or stdin]

 -f 忽略大小写差异,

-b:忽略前面的空格部分
-M
以月份的名字排序,
-n
使用数字进行排序

-r 反向排序

-u uniq相同的数据中仅现一行代表

-t 分隔符,预设tab键来分隔

-K 以哪个区间来进行排序


cat /etc/passwd | sort -t':' -k 3

passwd打印出来之后排序用“:”风格并且取第三那个字符


root@timfeng-desktop:/etc#last|cut -d ' ' -f1|sort|uniq -c
      1
      2 reboot
    13 root
      1wtmp

仅显示登陆账户,并且只显示一次,并且统计显示的次数



WC

列出行数,字数,字符数

/etc# cat/etc/manpath.config |wc
    131    715    5173


tee
会同事吧数据流分到档案于屏幕

tee [-a] file

-a用累加的方式加

last|tree last.list|cut -d ' '-f1   <==让我们可以将last的输出输入到文件last.list

tr

可以用来删除一段讯息当中的文字,或者是进行文字讯息的替换

tr[-ds] SET1

-d: 删除讯息当中的SET1这个字符串

-s 取代掉重复字符串

root@timfeng-desktop:~# cat/etc/passwd|tr -d ':'

/etc/passwd输出的讯息中,将冒号删除



join命令
  
功能:“将两个文件中指定栏位相同的行连接起来”,即按照两个文件中共同拥有的某一列,将对应的行拼接成一行。
 join[options] file1 file2

paste[-d] file1 file2

将两个文件相同行连接在一起










發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章