M'nkhani yotsatira tidzawona zina zida zama mzere ogwiritsa ntchito kuti mupeze zingwe kapena mitundu yofananira mkati mwa mafayilo. Zida izi zimagwiritsidwa ntchito molumikizana ndi mawu wamba, achidule monga Zotsatira REGEX, Zomwe ndizingwe zapadera zofotokozera zosaka.
Mawu okhazikika ndi mitundu yomwe imagwiritsidwa ntchito kuti mupeze kuphatikiza kwakatundu kazenera. Mawu okhazikika amapereka njira yosinthira pakusaka kapena kuzindikira zingwe zolembedwa. Ngakhale m'mizere yotsatira sitidzawona mawu wamba, tidzagwiritsa ntchito mitundu kapena zingwe.
Zotsatira
Sakani zingwe kapena mitundu kuchokera ku terminal
Lamulo la Grep
Grep ndichidule cha Sindikizani Pafupipafupi Padziko Lonse. Ichi ndi chida champhamvu chomenyera chomwe chimathandiza posaka chingwe kapena mtundu winawake mu fayilo. Ndi grep tidzatha kugwiritsa ntchito ntchito zosiyanasiyana, monga zomwe mnzathu adatifotokozera mu buloguyi kanthawi kapitako.
Mawu omasulira ogwiritsa ntchito grep ndiwosavuta:
grep PATRON [RUTA AL ARCHIVO]
Mwachitsanzo, kusaka chingwe 'Ubuntu'mu fayilo yomwe tichitane muchitsanzo ichi malemba.txt, osaganizira kusiyana pakati pamakalata apamwamba ndi apansi, mu terminal (Ctrl + Alt + T) tiyenera kuchita lamuloli:
grep -i Ubuntu texto.txt
Lamulo sed
Ludzu ndi lalifupi Mkonzi Wotsatsa. Ndi chida china chothandizira pa terminal yomwe titha kupezera zolemba mufayilo. Kusaka kwa sed, zosefera ndikusintha zingwe mu fayilo yomwe yapatsidwa.
Lamulo la sed mwachinsinsi limasindikiza zomwe zikutulutsidwa mu KUDULA (Standard linanena bungwe). Izi zikutanthauza kuti zotsatira za kuphedwa zimasindikizidwa kumalo osungira m'malo mopulumutsidwa ku fayilo.
Lamulo la Sed lingagwiritsidwe ntchito motere:
sed -OPCIONES COMANDO [RUTA AL ARCHIVO]
Mwachitsanzo, m'malo mwa zochitika zonse za 'Linux'm'malemba ndi'Linux', lamulo logwiritsa ntchito lingakhale ili:
sed 's/Linux/GnuLinux/g' texto.txt
Ngati zomwe tikufuna ndi yambitsiraninso zotulutsa ku fayilo m'malo mozisindikiza ku terminal, tigwiritsa ntchito chikwangwani choperekera motere:
sed 's/Linux/GnuLinux/g' texto.txt > salida.txt
Zotsatira za lamuloli zimasungidwa mu fayilo zotulutsa.txt m'malo mosindikizidwa pazenera.
Kuti muwone zambiri, mutha onani masamba amunthu:
man sed
ack
Ack ndi chida chofulumira chomenyera cholembedwa ku Perl. Imawerengedwa kuti ndiubwino m'malo mwa grep utility, zomwe zimapangitsanso zotsatira m'njira yooneka bwino.
Para kukhazikitsa ack m'dongosolo lathu tidzayenera kuchita mu terminal (Ctrl + Alt + T):
sudo apt install ack
Lamulo Ack amasaka fayilo kapena chikwatu cha mizere yomwe ili ndi machesi pazosaka. Kenako onetsani chingwe chofananira. Chida ichi chimatha kusiyanitsa mafayilo kutengera zowonjezera zawo.
Mawu omasulira a lamulo la Ack angakhale ngati awa
ack [OPCIONES] PATRÓN [RUTA AL ARCHIVO]
Mwachitsanzo, kusaka teremu Linux mu fayilo, tiyenera kuchita:
ack Linux texto.txt
Chida chofufuzira ndichabwino komanso ngati wosuta satenga mafayilo kapena zolemba zilizonse, imasanthula zolemba zomwe zili pano ndi ma subdirectories pazosaka.
Mu chitsanzo chotsatira, palibe fayilo kapena chikwatu chomwe chimaperekedwa. Ack amangozindikira fayilo yomwe ilipo m'ndandanda ndikusaka mtundu wofananira:
ack Linux
ripgrep
ripgrep ndizogwiritsa ntchito pamtanda pofufuza njira zowonekera pafupipafupi. Imathamanga kuposa zida zonse zakusaka zomwe zatchulidwa pamwambapa, ndipo imasanthula zolemba zawo mobwerezabwereza kuti zifanane. Ikuthandizani kuti mufufuze mitundu ina ya mafayilo. Pokhapokha, ripgrep imadumpha ma binaries ndi mafayilo obisika / zikwatu.
Para kukhazikitsa ripgrep pa dongosolo, zonse muyenera kuchita ndikutsatira lamulo ili mu terminal (Ctrl + Alt + T):
sudo apt install ripgrep
Chidule chogwiritsa ntchito ripgrep ndichachidziwikire:
rg [OPCIONES] PATRÓN [RUTA AL ARCHIVO]
Ngati tikufuna kusaka unyolo 'Linux'm'mafayilo omwe ali m'ndandanda wamakono, tidzangopereka lamulo:
rg Linux
Kuti muwone zosankha zambiri, ogwiritsa ntchito amatha kugwiritsa ntchito masamba amunthu:
man rg
Wofufuza Siliva
Para kukhazikitsa chida ichiMu Ubuntu tiyenera kutsegula terminal (Ctrl + Alt + T) ndikulemba lamulo:
sudo apt install silversearcher-ag
Wofufuza Silver ndi nsanja yolumikizira, chida chotsegula chotsegula chofanana ndi ack koma ndikugogomezera kuthamanga. Zimapangitsa kukhala kosavuta kupeza chingwe chapakatikati mwa mafayilo munthawi yochepa kwambiri. Mawu omasulira omwe mungagwiritse ntchito ndi awa:
ag OPCIONES PATRÓN_DE_BÚSQUEDA /ruta/al/archivo
Mwachitsanzo, kusaka 'Linux'mu Fayilo malemba.txt, tiyenera kulemba mu terminal (Ctrl + Alt + T):
ag Linux texto.txt
Kuti muwone zambiri zomwe mungachite titha kufunsa masamba amunthu:
man ag
Izi ndi zina mwazomwe zidagwiritsidwa ntchito kwambiri pofufuza, kusefa, ndikuwongolera ma Linux.
Khalani oyamba kuyankha