关于SED:
修改第23行的内容:sed -i '23s/Applications/reb_app/g' reb_test.txt
删除最初三行:sed -i '1,3d' reb_test.txt
显示第二行:sed -n '2p' reb_test.txt
显示一个文件中1/3/5行中每行第1~5个字符:sed -n "1p;3p;5p" reb_test.txt | cut -c 1-5
打印出文件的前三行:head -n3 reb_test.txt or sed -n "1,3p" reb_test.txt or sed "3q" reb_test.txt
打印出文件里面的全部内容:awk '{print}' ./reb_test.txt
用/分割的第一部分($1)和第三部分($3):awk -F "/" '{print $1 $3}' ./reb_test.txt
显示文件的1/3行:awk 'NR==1 || NR==3{print $0}' reb_test.txt
关于CUT:
rebcheng@beleod22 shell $ who | grep rebcheng | head -n 3
rebcheng pts/8 2014-06-30 09:24 (10.220.115.102:6.0)
rebcheng pts/11 2014-08-15 09:33 (10.220.115.102:6.0)
rebcheng pts/58 2014-06-30 12:29 (10.220.115.102:6.0)
rebcheng@beleod22 shell $ who | grep rebcheng | head -n 3 | cut -b 6
e
e
e
rebcheng@beleod22 shell $ who | grep rebcheng | head -n 3 | cut -b -6
rebche
rebche
rebche
rebcheng@beleod22 shell $ who | grep rebcheng | head -n 3 | cut -d . -f 1
rebcheng pts/8 2014-06-30 09:24 (10
rebcheng pts/11 2014-08-15 09:33 (10
rebcheng pts/58 2014-06-30 12:29 (10
rebcheng@beleod22 shell $ who | grep rebcheng | head -n 3 | cut -d . -f 2
220
220
220
下面是转载的,没有自己试过:
[rocrocket@rocrocket programming]$ cat cut_ch.txt
星期一
星期二
星期三
星期四
[rocrocket@rocrocket programming]$ cut -b 3 cut_ch.txt
�
�
�
�
[rocrocket@rocrocket programming]$ cut -c 3 cut_ch.txt
一
二
三
四
看到了吧,用-c则会以字符为单位,输出正常;而-b只会傻傻的以字节(8位二进制位)来计算,输出就是乱码。
cut有哪些缺陷和不足:cut只擅长处理“以一个字符间隔”的文本内容。在处理多空格时有问题。