2010年7月27日 星期二

資料處理

# ifconfig | grep 'inet addr' | tr -s ' '
inet addr:192.168.200.140 Bcast:192.168.200.255 Mask:255.255.255.0
inet addr:127.0.0.1 Mask:255.0.0.0

grep 將含有inet addr的資料列出
tr -s ' ' 將多個空白變成一個空白

cut 剪取自己想要的資料
# ifconfig | grep 'inet addr' | cut -d' ' -f2
代表從第一個空白開始算的第二個字串
# ifconfig | grep 'inet addr' | cut -d':' -f3
代表從第一個分號開始算的第三個字串

 od 檢視檔案的原始資料

# od –t  a  od.txt (原始表示 (sp=空白 nl=換行
0000000  a  1  sp  nl  A  1  sp  nl

# od –t  x1  od.txt (用16進位表示
0000000  61  31  20  0a  41  32  20  0a

wc 顯示檔案的行數 單字數 位元

先用cat看檔案內容
srv2adm@ubuntuSV02:~$ cat /etc/resolv.conf
nameserver 172.27.3.1
domain localdomain
search localdomain
再用wc去算該檔 得知有3行 6個單字 60個位元
srv2adm@ubuntuSV02:~$ wc /etc/resolv.conf
 3  6 60 /etc/resolv.conf

tail 檢視檔案底部的內容

預設顯示10行
# tail  ~/.bash_history
顯示3行
# tail  -n3  ~/.bash_history

沒有留言:

張貼留言