Awk: Te Ako Hoko Hoko Ma te whakamahi i te Whakahau Terminal Terminal

Awk: Te Ako Hoko Hoko Ma te whakamahi i te Whakahau Terminal Terminal

Awk: Te Ako Hoko Hoko Ma te whakamahi i te Whakahau Terminal Terminal

Ko te whakahau "awk" kei roto i nga Punaha Whakahaere Koreutu o te momo GNU / Linux he tino mana te whakahau, hei awhina i a maatau ki te whakahaere i a tatou ki te whakahaere i nga raraunga mai i etahi atu whakahau, whakahau ranei. Ko te ingoa AWK i ahu mai i nga ingoa tuatahi o nga ingoa o ona kaituhi: Alfred Aho, peterata Weinberger, me Brian Kernighan.

Ko tenei whakahau he reo tuhi mo te tukatuka tuhinga e taea ai e taatau: Te tautuhi i nga taurangi, te whakamahi i nga aho me nga kaiwhakahaere tauanga, whakamahi i te rere rere me nga huringa, me te whakaputa purongo whakatakotoranga. Ae ra, ko te Awk he mea nui ake i te whakahau tukatuka tauira, he reo wetiweti katoa te reo.

Whakataki ki te whakahau "awk"

Ko te AWK tetahi o nga taputapu papatohu rongonui rongonui hei whakahaere (hapai / tango) i nga raraunga ma te whakanui i nga mahi o nga putunga UNIX. Ko te reo e tukuna ana e tenei mahinga he paerewa kei roto i te nuinga o nga punaha Whakahaere-momo UNIX hou, no reira he waahanga no nga UNIX Whakatakotoranga taketake, na reira i te nuinga o te waa kua whakauruhia ki te nuinga o raatau ma te taunoa.

Ko te tikanga o te wetiweti ko te: awk 'papatono' konae konae me te wahi ko te 'hotaka': tauira {mahi} tauira {mahi} Ma te whakahau e panui te konae ki te whakauru i nga raina kotahi. Ko ia rarangi ka whakataurite ki ia tauira i runga i te raupapa Mo ia tauira e taurite ana ki te haupae, ka mahia nga mahi e rite ana.

He tauira ngawari penei:

awk -F: '$1=="root" {print}' /etc/passwd

ka patai ia mo te mara tuatahi mena he putake o ia raina ki / etc / passwd ka taarua ana ka whakaarohia te ":" me -F: hei wehenga mara.

Tauira Whakataki Awk

He tauira whaihua

Rarangi o nga whakahau e tino whakamahia ana

Tirohia te raarangi e pa ana ki te hitori o te teihana Punaha kua ota mai i te nuinga o te waa ki te iti.

history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head

Hei tauira:

Tauira 1: Awk whakahau

Kauwhata (Ripanga) me te maha o nga hononga mo ia kaihautu

Hangaia he kauwhata tuhinga-tuhi ASCII e whakaatu ana i te maha o nga hononga mai i te kaihautu ki ia wahitau IP.

netstat -an | grep ESTABLISHED | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | awk '{ printf("%s\t%s\t",$2,$1) ; for (i = 0; i < $1; i++) {printf("*")}; print "" }'

Hei tauira:

Tauira 2: Awk whakahau

Rarangi o nga Whaiaronga i te rahi

Taia ki runga i te papa te raarangi o nga raarangi o te ara o naianei mai i te rahi ki te iti rawa e whakaatu ana i nga tapanga e rite ana ki te rahi ma te whakamahi i nga reta: g, m, me te k.

du --max-depth=1 | sort -r -n | awk '{split("k m g",v); s=1; while($1>1024){$1/=1024; s++} print int($1)" "v[s]"\t"$2}'

Hei tauira:

Tauira 3: Awk whakahau

Whakaatuhia te hokohoko mai i te Atanga Whatunga

Tirohia te kohinga raraunga a roto me waho o te ipurangi ki te kilobytes (kb) mo te hononga whatunga kua tohua.

while [ /bin/true ]; do OLD=$NEW; NEW=`cat /proc/net/dev | grep eth0 | tr -s ' ' | cut -d' ' -f "3 11"`; echo $NEW $OLD | awk '{printf("\rin: % 9.2g\t\tout: % 9.2g", ($1-$3)/1024, ($2-$4)/1024)}'; sleep 1; done

Hei tauira:

Whiwhi mai i te raarangi nama fibonacci

Hangaia he raarangi o te rahinga X e whai ake nei i te tauira aurere kua hoatu kia 2 nga tau turanga hei hanga.

seq 50| awk 'BEGIN {a=1; b=1} {print a; c=a+b; a=b; b=c}'

Hei tauira:

Tauira 5: Awk whakahau

Raarangi whakairoiro o te hanganga o te konae ma te rahi

Tiki he Rarangi o nga kōpaki katoa i te pakiaka o te punaha whakahaere me te whakairoiro (tutaki) me te tohu taatai ​​hei ōrau o te rahi kei roto.

t=$(df|awk 'NR!=1{sum+=$2}END{print sum}');sudo du / --max-depth=1|sed '$d'|sort -rn -k1 | awk -v t=$t 'OFMT="%d" {M=64; for (a=0;a<$1;a++){if (a>c){c=a}}br=a/c;b=M*br;for(x=0;x<b;x++){printf "\033[1;31m" "|" "\033[0m"}print " "$2" "(a/t*100)"% total"}'

Hei tauira:

Tauira 6: Awk whakahau

Rarangi whakarapopototanga o nga momo konae ki tetahi Whaiaronga

Whakaatuhia he raarangi o nga momo konae kei roto i te raarangi whaiaronga me te maha o nga konae e hangai ana ki a ia.

find . -type f | awk -F'.' '{print $NF}' | sort| uniq -c | sort -g

Hei tauira:

Tauira 8: Awk whakahau

Ko enei tauira o nga raina whakahau ma te whakamahi i te whakahau awe ko te tumanako he tino whai hua koe. Ana ka whakamahia ki te whakamahi tika mai i te papatohu, kaore ranei ma te whakauru ki roto ki te tuhinga (mahi aunoa).

I roto i te panui e whai ake nei i runga i te Kaituhi Papa ka tirohia e maatau etahi atu whakahau.

Mena kei te hiahia koe ki te ako mo etahi atu korero mo te whakahau "grep" tirohia tenei hono hono "DEBIAN Wiki”Ana mena kei te hiahia koe ki te ako atu mo te Huri Papaanga i ta maatau ake Blog, ka taea e koe te titiro ki etahi atu panui mo tenei kaupapa, ma te paatene i konei: Te tuhi i roto i te MaiLinux


Ko nga korero o te tuhinga e piri ana ki o maatau kaupapa o matatika whakatika. Ki te ripoata i tetahi paatene paato Here.

He korero, waiho i a koe

Waiho to korero

Ka kore e whakaputaina tō wāhitau īmēra. Kua tohua ngā āpure e hiahiatia ana ki *

*

*

  1. He kawenga mo nga raraunga: Miguel Ángel Gatón
  2. Te kaupapa o te raraunga: Whakahaerehia te SPAM, te whakahaere korero.
  3. Ture: To whakaae
  4. Whakawhitinga korero: Kaore nga korero e tukuna ki nga taha tuatoru engari ma te ture herenga.
  5. Rokiroki raraunga: Paetukutuku e whakahaerehia ana e Occentus Networks (EU)
  6. Tika: I nga wa katoa ka taea e koe te whakaiti, te whakaora me te muku i o korero.

  1.   Tuxito ka mea

    I maarama noa ahau ki te tauira tuatahi, kaore he mea ke atu 🙁