Linux shell命令(2) - cat/cut/paste/sed/tr/grep/sort/uniq
2007-11-04 23:01
726 查看
who
alluserscurrentlyloggedintothesystem
cat
examinethecontentsofafile
wc-l
wc-w
wc-c
getacountofthetotalnumberoflines,words,andcharactersofinformationcontainedinafile
-dand-foptions
以-d指定分界符将参数分成多个field,-f指定哪几个field
不指定分界符,则以tab为分界符
*,?都可运用到模式串和文件名
正则表达式例子:
grep–i忽略匹配大小写
grep-v找出不匹配模式串的行
grep-l仅列出包含模式串的文件
grep-n额外给出匹配的行号
sort-u去除重复项
sort-r逆向排序
sort-o重定向到文件sortnames-osorted_names等价于sortnames-o>sorted_names
sort-n算术排序,而非字符排序
sort+1n跳过第1个field,然后算术排序
sort-t指定分界符来分隔field,通常sort+1n这类都默认以space或tab为分隔符
alluserscurrentlyloggedintothesystem
cat
examinethecontentsofafile
wc-l
wc-w
wc-c
getacountofthetotalnumberoflines,words,andcharactersofinformationcontainedinafile
cut
cut-ccharsfile$who
rootconsoleFeb2408:54
stevetty02Feb2412:55
georgetty08Feb2409:15
dawntty10Feb2415:55
$who|cut-c1-8Extractthefirst8characters
root
steve
george
dawn
$
$who|cut-c1-8,18-
rootFeb2408:54
steveFeb2412:55
georgeFeb2409:15
dawnFeb2415:55
$
-dand-foptions
以-d指定分界符将参数分成多个field,-f指定哪几个field
不指定分界符,则以tab为分界符
$cat/etc/passwd
root:*:0:0:TheSuperUser:/:/usr/bin/ksh
cron:*:1:1:CronDaemonforperiodictasks:/:
bin:*:3:3:Theownerofsystemfiles:/:
uucp:*:5:5::/usr/spool/uucp:/usr/lib/uucp/uucico
asg:*:6:6:TheOwnerofAssignableDevices:/:
steve:*:203:100::/users/steve:/usr/bin/ksh
other:*:4:4:Neededbysecureprogram:/:
$cut-d:-f1/etc/passwdExtractfield1
root
cron
bin
uucp
asg
steve
other
$cut-d:-f1,6/etc/passwdExtractfields1and6
root:/
cron:/
bin:/
uucp:/usr/spool/uucp
asg:/
steve:/users/steve
other:/
$
grep
greppatternfiles搜索模式串*,?都可运用到模式串和文件名
正则表达式例子:
grep'[A-Z]'list | Linesfromlistcontainingacapitalletter |
grep'[0-9]'data | Linesfromdatacontaininganumber |
grep'[A-Z]...[0-9]'list | Linesfromlistcontainingfive-characterpatternsthatstartwithacapitalletterandendwithadigit |
grep'\.pic$'filelist | Linesfromfilelistthatendin.pic |
grep-v找出不匹配模式串的行
grep-l仅列出包含模式串的文件
grep-n额外给出匹配的行号
sort
排序sort-u去除重复项
sort-r逆向排序
sort-o重定向到文件sortnames-osorted_names等价于sortnames-o>sorted_names
sort-n算术排序,而非字符排序
sort+1n跳过第1个field,然后算术排序
sort-t指定分界符来分隔field,通常sort+1n这类都默认以space或tab为分隔符
相关文章推荐
- 几个常用的文本处理shell 命令:find、grep、xargs、sort、uniq、tr、cut、paste、wc、sed、awk
- Linux管线命令 - cut,grep,sort,uniq,wc,tee,tr,col,join,paste,expand,split,xargs
- centos shell基础 alias 变量单引号 双引号 history 错误重定向 2>&1 jobs 环境变量 .bash_history source配置文件 nohup & 后台运行 cut,sort,wc ,uniq ,tee ,tr ,split, paste cat> 2.txt <<EOF 通配符 glob模式 发邮件命令mail 2015-4-8 第十二节课
- cut,paste,sed,tr,grep,uniq,sort
- Linux管线命令 - cut,grep,sort,uniq,wc,tee,tr,col,join,paste,expand,split,xargs
- Linux下Bash的管线pipe命令,cut,grep,sort,wc,uniq,tee,tr,col,join,past,expand
- 学习cat sort grep cut sed uniq find less
- (三) paste 之grep cut paste sort awk sed find uniq 全面总结
- shell工具——cut、tr、grep、sort、uniq、re、sed、awk
- grep,tr,cut,sort,uniq命令详解
- (四)find 之grep cut paste sort awk sed find uniq 全面总结
- linux下常用的几个工具 (cut, uniq, wc, grep, sort, tr, paste)
- Linux grep sed nl awk sort,uniq,cut,wc rsync命令详解
- Linux下Bash的管线pipe命令,cut,grep,sort,wc,uniq,tee,tr,col,join,past,expand
- linux下常用的几个工具 (cut, uniq, wc, grep, sort, tr, paste)
- linux下常用的几个工具 (cut, uniq, wc, grep, sort, tr, paste)
- linux cat,tac,more,less,head,tail,cut,sort,uniq,wc,tr命令的使用
- linux基础篇-07,linux文本处理cat more less head tail sort uniq grep cut jion sed awk
- grep,tr,cut,sort,uniq命令详解
- shell 知识点补充(2)-重定向/ ; , &&, ||/管线命令/grep/sort/ uniq/wc/tee/tr/col/join/paste/expand/split/-