您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 公司方案 > linux_shell_awk
Awk1[]developerWorksLinuxAwk1awkawkBEGINEND:developerWorksDanielRobbinsCEO,GentooTechnologies,Inc.200012AwkDanielRobbinsawkawkawkawkawk“”awkGNUgawkawkUNIXkill-9!awkawkawkCpythonbashawkpythonbashawkawkawk$awk'{print}'/etc/passwd/etc/passwdawkawk/etc/passwdawk/etc/passwdprintstdoutcatting/etc/passwd{print}awkCprintawkprintawk(1of9)2005-5-2715:46:43Awk1$awk'{print$0}'/etc/passwdawk$0printprint$0awk$awk'{print}'/etc/passwdprint/etc/passwdawkawk$awk'{printhiya}'/etc/passwdhiya:)awkawk$awk-F:'{print$1}'/etc/passwdawk-F:awkprint$1$awk-F:'{print$1$3}'/etc/passwdhalt7operator11root0shutdown6sync5bin1....etc.awk/etc/passwd--bashpythonprint$1$3awkawk(2of9)2005-5-2715:46:43Awk1$awk-F:'{print$1$3}'/etc/passwdprint$1$3$awk-F:'{printusername:$1\t\tuid:$3}'/etc/passwdusername:haltuid:7username:operatoruid:11username:rootuid:0username:shutdownuid:6username:syncuid:5username:binuid:1....etc.awkawk-f$awk-fmyscript.awkmyfile.inawk/etc/passwdBEGIN{FS=:}{print$1}FSawk-F:FSFSBEGINENDawkawkawkBEGINBEGINawkBEGINFS(3of9)2005-5-2715:46:43Awk1awkENDawkENDawkfoo/foo/{print}/[0-9]+\.[0-9]*/{print}awkfredfredawkprint$1==fred{print$3}awk====!=awk~!~“”“”root$5~/root/{print$3}awkCifif{if($5~/root/){print$3}}ifprint(4of9)2005-5-2715:46:43Awk1awkififCif{if($1==foo){if($2==foo){printuno}else{printone}}elseif($1==bar){printtwo}else{printthree}}if!/matchme/{print$1$3$4}{if($0!~/matchme/){print$1$3$4}}matchmeawk||&&($1==foo)&&($2==bar){print}foobarawkBEGIN{x=0}/^$/{x=x+1}END{printIfoundxblanklines.:)}(5of9)2005-5-2715:46:43Awk1BEGINxawkawkx=x+1xENDawkawk“”awk“”awkawk“”awkx=1.01#Wejustsetxtocontainthe*string*1.01x=x+1#Wejustaddedonetoa*string*printx#Incidentally,thesearecomments:)awk2.011.01xbashpythonbashbash“”“”bash$())python1.01awk{print($1^2)+1}awkawkawk^%Ci++--fooa+=3b*=2c/=2.2d-=6.2--a^=2b%=4awkawkFSawk/etc/passwdFS:FSFStabFS(6of9)2005-5-2715:46:43Awk1FS=\t++“”tabFSFS=[[:space:]+]FSawk“tab”FSfooFS=foo[0-9][0-9][0-9]NF“”awkNFNF==3{printthisparticularrecordhasthreefields:$0}NF{if(NF2){print$1$2:$3}}(NR)awk1NRNFNR(NR10)||(NR100){printWeareonrecordnumber1-9or101+}(7of9)2005-5-2715:46:43Awk1{#skipheaderif(NR10){printok,nowfortherealinformation!}}awkawkawkawk●developerWorks.●O'Reillysed&awk,2ndEdition●comp.lang.awkFAQawk●PatrickHartiganawktutorialawk●Thompson'sTAWKCompilerawkWindowsOS/2DOSUNIX●TheGNUAwkUser'sGuideDanielRobbinsAlbuquerqueGentooTechnologies,Inc.CEOGentooLinuxPCLinuxPortageLinuxMacmillanCalderaOpenLinuxUnleashedSuSELinuxUnleashedSambaUnleashedDanielLogoPac-ManSONYElectronicPublishing/PsygnosisDanielMaryHadassahdrobbins@gentoo.orgDaniel(8of9)2005-5-2715:46:43Awk1(1)(2)(3)(4)(5)developerWorksLinuxIBMIBM(9of9)2005-5-2715:46:43Awk2[]developerWorksLinuxAwk2OFSORStabbreakcontinue:developerWorksDanielRobbinsCEO,GentooTechnologies,Inc.20011awkDanielRobbinsawkDanielawkawkawkawk/etc/passwd/etc/passwdUNIXawkFS:FSawkFSRSRSawk“”JimmytheWeasel100PleasantDriveSanFrancisco,CA12345BigTony200IncognitoAve.Suburbia,WA67890awk3awk($1)($2)$3(1of8)2005-5-2715:46:14Awk2BEGIN{FS=\nRS=}FS\nawkRSawkawkaddress.awkBEGIN{FS=\nRS=}{print$1,$2,$3}address.awkaddress.txtawk-faddress.awkaddress.txtJimmytheWeasel,100PleasantDrive,SanFrancisco,CA12345BigTony,200IncognitoAve.,Suburbia,WA67890OFSORSaddress.awkprintawk(,),awkOFSawkprintHello,there,Jim!awkHellothereJim!OFSawkHellothereJim!OFSOFSawkaddress.awkOFS,address.awk(2of8)2005-5-2715:46:14Awk2BEGIN{FS=\nRS=OFS=,}{print$1,$2,$3}awkORS“”(\n)OFSprintORSawkprintORS\n\nORStabtabaddress.awkawkCousinVinnieVinnie'sAutoShop300CityAlleySosueme,OR76543address.awkBEGIN{FS=\nRS=ORS=}{x=1while(xNF){print$x\tx++}print$NF\n}FS\nRSawkORSprintprint\nx1whileawkCwhiletabORSprinttab(3of8)2005-5-2715:46:14Awk2JimmytheWeasel100PleasantDriveSanFrancisco,CA12345BigTony200IncognitoAve.Suburbia,WA67890CousinVinnieVinnie'sAutoShop300CityAlleySosueme,OR76543awkwhileCwhileawkdo...whilewhilerepeat...untildo...while{count=1do{printIgetprintedatleastoncenomatterwhat}while(count!=1)}whiledo...whilewhileforawkforwhileCforfor(initialassignment;comparison;increment){codeblock}for(x=1;x=4;x++){printiteration,x}iteration1iteration2iteration3iteration4breakcontinueCawkbreakcontinue
本文标题:linux_shell_awk
链接地址:https://www.777doc.com/doc-6105185 .html