egrep: izibonelo zomyalo ku-GNU / Linux

egrep

i-grep ingenye yamathuluzi asetshenziswe kakhulu kulayini womyalo we-GNU / Linux. Yize ulithuluzi elilula kakhulu, likuvumela ukuthi wenze imisebenzi eminingi. Isetshenziswa ikakhulukazi ngokuhlangana namapayipi, ukuthola amaphuzu athile ekukhishweni komyalo wangaphambilini, njll. Kepha kukhona futhi ithuluzi elaziwa njenge-egrep elilingana nokusebenzisa i-grep ngenketho ye -E.

I-e ivela ku "Regex enwetshiwe", okuyiyona eyenza kusebenze inketho ye -E nokuthi yini onayo ku-egrep ngokuzenzakalela ngaphandle kokusebenzisa leyo nketho. Lokho wukuthi, ungasebenzisa i- izinkulumo ezivamile. Kulesi sifundo ngeke ngichaze ukuthi iziphi izinkulumo ezijwayelekile, ukuthi zingasetshenziswa kanjani nokuthi yiziphi izinhlobo eziku- * nix. Ngizovele ngikhombise izibonelo ezisebenzayo zezinto ezithile ezilusizo ongazenza nge-egrep ...

i-grep, i-egrep ne-fgrep ziyefana. Eqinisweni, i-egrep ilingana ne-grep -E futhi i-fgrep ilingana ne-grep -F. Lokho wukuthi, esimweni esithinta thina, kuzophinda kuhumushe amaphethini njengezincazelo ezijwayelekile.

Ungakwazi sesha umugqa noma igama kufayela elilodwa noma amaningi, njengoba kunjalo nge-grep. Isibonelo, ake sithi ufuna ukusesha igama ubuntu kufayela elibizwa nge-snap.txt nakuwo wonke amafayela we-.txt enkombeni yamanje:

egrep ubuntu snap.txt

egrep ubuntu *.txt

Ukucinga nakho kungaba kuyaphinda Ukusesha konke okuqukethwe umkhombandlela wamanje:

egrep -r "hola mundo" *

Kuze kube manje, kuseshwe amagama ngqo noma izintambo, okusho ukuthi, kucatshangelwa icala eliphezulu neliphansi (elibucayi), kepha uma ufuna ukukwenza uma ungazweli, akunandaba noma ngabe zingosonhlamvukazi noma izinhlamvu ezincane, ungasebenzisa okulandelayo (uma ungeza ukuthola kuphela ukufana okuphelele):

egrep -i "ejemplo" documento.txt

egrep -iw "ejemplo" documento.txt

Khombisa, hhayi ukuqondana kwezinto, kodwa amagama wamafayela lapho kutholakala khona lokho okufanayo:

egrep -l hola *.txt

Khombisa kuphela iphethini noma igama kuseshwe embhalweni:

egrep -o printf hola.c

Khumbula ukuthi ungasebenzisa wonke amathuba ongawacabanga. Ungahlanganisa izinketho eziningi ezibonwe phambilini, noma ungazihlanganisa nezinye izinketho ezifana ne -A n ne -B n, lapho n inani lemigqa ofuna ukuyikhombisa ngaphambili (Ngaphambi) nangemva (Ngemuva) yomdlalo noma womabili ngasikhathi sinye (C), ukuze ukwazi ukubona ukuthi yini ezungeze umdlalo:

egrep -A 2 "printf" hola.c

egrep -B 2 "printf" hola.c

egrep -C 2 printf hola.c

Cindezela imigqa equkethe umentshisi bese ukhombisa kuphela leyo engafani.

egrep -v "dos" números.doc

Noma uma uthanda, ungasebenzisa amagama amaningi noma ukufana no -e. Isibonelo:

egrep -v -e "uno" -e "dos" -e "tres" números.txt

Uma usebenzisa -c ingabala kuphela inani lemidlalo, noma uyiguqule nge -v ukukhombisa inani lemigqa engalingani. Ngokwesibonelo:

egrep -c "include" main.c

egrep -v -c "include" main.c

Futhi ngisho bonisa inombolo yomugqa lapho umdlalo wenzeke khona, kanye nesimo okuso ngokulandelana:

egrep -n "void" hola.c

egrep -o -b "printf" hola.c

Futhi kanye ne izinkulumo ezivamile amakhono ayo anganwetshwa. Isibonelo, thola umugqa oqala ngo-Hello bese uphela ngo-bye, noma oqala ngo-Hello olandelwa yinoma yini bese umeshi womdlalo uvela ngokulandelana:

* Ukulungiswa komyalo olandelayo: ngenxa yokuphawula komfundi uManuel Alcocer ngikwazile ukuguqula umyalo olandelayo, ngoba kube nephutha.

egrep '^Hola.*adiós$' ejemplo.txt

egrep "Hola.*adiós" ejemplo.txt

Kepha uma uzibuza ngomehluko nge-grep, nasi isibonelo esizokucacisela ... Esimweni sokusebenzisa i-grep ngaphandle -E kufanele usebenzise i- ukulandelana kokuphunyuka ukuze ihumushe abalingiswa abakhethekile kanjalo, ngaphandle kwalokho ibingahumusha iphethini kanjalo ngaphandle kokubheka. Ngakolunye uhlangothi, nge-egrep noma i-grep -E kuzobacabangela. Ngokwesibonelo:
grep '^no\(fork\|group\)' /etc/group

Lokho kungalingana no:

grep -E '^no(fork|group)' /etc/group
egrep '^no(fork|group)' /etc/group

Lokho wukuthi, kungabheka imigqa efanayo eqala nge-nofork noma ngeqembu. Kepha uma usebenzise isisho sokuqala se-grep ngaphandle kokulandelana kokuphunyuka, obekuzokwenza ukusesha iphethini kakhonkolo cha (imfoloko | iqembu):

grep 'no(fork|group)' /etc/group

Ungasesha futhi amabanga ezinombolo, noma amanani athile, njengokuthola ama-IP athile:
cat /etc/networks | egrep "192.168.1.[5-9]"
cat /etc/networks | egrep "192.168.[1-3].[5-9]"
cat /etc/networks | egrep "192.168.1.[0-3]|[5-9]"
egrep 192.168.4.[10,40] networks

Uma uthanda, ungasebenzisa ezinye izinkulumo ezivamile ukwenza usesho oluthile. Isibonelo | ukuthola eyodwa ukuqondana noma okunye:

egrep -i '^(printf|scanf)' hola.c

Ungakwazi ngisho nokuthola osonhlamvukazi abakhulu, izinhlamvu ezincane, izinhlamvu zamagama kuphela, noma i-alphanumeric, njll., usebenzisa ezinye izinkulumo ezinjenge: [: alnum:], [: alpha:], [: idijithi:], [: lower:], [: phrinta:], [: punct:], [: space:], [: engenhla:], njll. Isibonelo, ukusesha onobumba abakhulu:
egrep [[:upper:]] diccioario

Ngiyethemba ukuthi iyakusiza ... Maduze ngizochaza izinkulumo ezijwayelekile endatshaneni enikelwe yona ngqo ...


Okuqukethwe yi-athikili kunamathela ezimisweni zethu ze izimiso zokuhlelela. Ukubika iphutha chofoza lapha.

Amazwana ayi-5, shiya okwakho

Shiya umbono wakho

Ikheli lakho le ngeke ishicilelwe. Ezidingekayo ibhalwe nge *

*

*

  1. Ubhekele imininingwane: Miguel Ángel Gatón
  2. Inhloso yedatha: Lawula Ugaxekile, ukuphathwa kwamazwana.
  3. Ukusemthethweni: Imvume yakho
  4. Ukuxhumana kwemininingwane: Imininingwane ngeke idluliselwe kubantu besithathu ngaphandle kwesibopho esisemthethweni.
  5. Isitoreji sedatha: Idatabase ebanjwe yi-Occentus Networks (EU)
  6. Amalungelo: Nganoma yisiphi isikhathi ungakhawulela, uthole futhi ususe imininingwane yakho.

  1.   UManuel Alcocer kusho

    Kuhle ntambama

    Amazwana ambalwa ...

    Uchaza umyalo 'we-egrep' kepha ungafaki umehluko phakathi kwe-'grep 'ne' grep ', okufanele kube yilokhu okukhona lapha.

    Isibonelo:
    Nge-grep: ip -4 a | i-grep '[0-9] \ +'
    Nge-egrep: ip -4 a | i-egrep '[0-9] +'

    Ahh, futhi lokhu akulungile, 'egrep "Sawubona. * Bye" example.txt'; impumelelo lapha yenzeka lapho kunolayini efayeleni oqukethe intambo ethi 'Sawubona' ulandelwe yinoma yini futhi ilandelwe ngu- 'sala kahle', umugqa ungaqala futhi uphele nganoma yini.

    Lokhu kungaba yilokhu okushiwo yilo mbhalo:
    egrep '^ Sawubona. * bye $' example.txt

    Futhi konke okukhethwa kukho, noma cishe konke (angimi ukukuhlola), kuyizinketho ze-'grep 'hhayi ze' egrep 'kuphela.

    Okuhle kakhulu

    1.    Isaka kusho

      Siyabonga ngokubika lelo phutha. Okuphawulayo ngezinkulumo ezijwayelekile, sengivele ngikubeke esigabeni sesibili. Ngizonikezela i-athikili ethile kubo, ngoba kuningi futhi le ndatshana izothatha isikhathi eside kakhulu. Ukubingelela!

      1.    UManuel Alcocer kusho

        Sawubona futhi, Isaac.

        Esigabeni sesibili ngokuyisisekelo usho, noma bekufanele ngabe usho ukuthi, 'i-egrep' iyi-alias ye-'grep -E ', kepha awuniki sibonelo sokusebenzisa i-'grep' ngesichasiso esijwayelekile esibhalwe ngokuhlukile kunangesikhathi isetshenziswe ngu 'grep'.

        Ukunikezela i-athikili ukuchaza izinkulumo ezijwayelekile ezinwetshiwe kubonakala kunesibindi kimi, phakathi kokunye ngoba kukhona amasayithi afana nalawa angakhangisi futhi enza umsebenzi obaluleke kakhulu wolwazi womphakathi we-GNU: https://www.rexegg.com/

        Angibhaleli lapha ukuthi nginyathele, inhloso yami ngakho konke lokhu ukuthi uma othile efunda lokhu kufakwa ukuze abone ukuthi yini i- 'egrep' noma 'grep', sicela ubheke eminye imithombo, lokhu kufakwa akukwazi ukubhekisela kunoma yini, kuchaza okuncane, kabi, kunikeza imininingwane engadingekile futhi kungadida, ikakhulukazi kulabo abangenalo ulwazi lwe-GNU namathuluzi anamandla elinikezayo.

        Ekugcineni, ungeze futhi walungisa isiphazamisi engisibonisile ngemuva kokuphawula kwami ​​kokuqala (^ $). Njengakwezinye izingosi, bekufanele ngabe ucaphune umuntu olungisile, noma okungenani uthi ukulungiswa, okuyingxenye yesisekelo se-GNU, isisekelo esifanayo nale blog esiqale ngaso futhi esenziwe ngaso elahlekile.

        A ukubingelela.

        1.    Isaka kusho

          Ngiyabonga ngombono wakho.

  2.   fsafs kusho

    ffsaf