24小时热门版块排行榜    

CyRhmU.jpeg
查看: 1405  |  回复: 5
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

probao

铁虫 (初入文坛)

[交流] 开始学习shell已有5人参与

最近对shell产生了浓厚的兴趣想系统地学习一下,并在小木虫记录下自己的学习过程。
先记录些以前的总结
grep
grep '[[:lower:]]' filename #lower-alpha
grep '\(ab\)\(cd\)[def]*\2\1 #find ab then cd then [def] then cd than ab houxiangyinyong

sed
sed 's/Tolstoy/Camus/' filename        #just change the first one
sed 's/Tolstoy/Camus/g' filename       #change all
sed 's/Tolstoy/Camus/2' filename       #change the second one
sed -n '3,5p' filename                 #print from line 3 to 5
sed '/xixi/,/haha/ s/baz/quux/g' filename   #find lines containing xixi and haha
                                            #then replace baz with quux in these lines
sed '/used/! s/new/used/g' filename    #find lines not containing used
sed '/^#/d' filename | sort > filename.sorted        #find lines containg # at the beginning
                                                #then delet

tail
tail -7 filename                       # print last 7 lines
tail -7 filename > 1                   # print last 7 lines in 1

cut
cut -b 3 filename                     # print the third byte from each line
cut -d : -f 1 filename                # -d customized separator -f field


joint
joint file1 file2                      # file1 and file2 should be in the same format
joint -a1 file1 file2                      # show the difference in file1


awk
awk -F: '{print $1,$2}' filename      # F--field separator print field 1 and 2
awk -F: -v 'OFS=**' '{print $1,$2}' filename        # v--variable OFS--output field sparator

sort
sort filename                              # sort according to ASCII
sort -u filename                      # sort according to ASCII and then delete repeated term
sort -r filename                      # descending order
sort filename -o filename              # sort and then print in the same file
sort -n filename                      # sort according to the number
sort -n -t : -k 2 filename              # -n sort according to the number -t consider colon as separator -k which row

uniq
sort latin-numbers | uniq              # no repeated lines
sort latin-numbers | uniq -c          # recorf repeated time
sort latin-numbers | uniq -d              # show the repeated term
sort latin-numbers | uniq -u          # show the non-repeated term

wc
wc -c                                      # calculate the number of bytes
wc -l                                      # calculate the number of lines
wc -w                                      # calculate the number of words
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

哈哈
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

Friday

新虫 (初入文坛)


小木虫: 金币+0.5, 给个红包,谢谢回帖
shell是linux嘛?windows能用吗?

发自小木虫Android客户端
3楼2016-01-24 17:09:50
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 probao 的主题更新
普通表情 高级回复(可上传附件)
信息提示
请填处理意见