Yadda tsari sake suna ɓangare na filename a Windows PowerShell amfani Regex? | show Top
Yadda tsari sake suna ɓangare na filename a Windows PowerShell amfani Regex?
A wannan misali, muna da 6 fayiloli a kasa tare da kwanan wata da filename kasa:
-wani ----       10/06/2018     12:40              0 1 = 9.8.16 Bankin Sirri 298.67.pdf
-A ----       10/06/2018     12:40              0 2 = 9.9.16 Bankin Sirri 134.74.pdf
-A ----       10/06/2018     12:41              0 3 = 9.10.16 Bankin Sirri 123.43.pdf
-A ----       10/06/2018     12:41              0 4 = 9.11.16 Bankin Sirri 134.54.pdf
-A ----       10/06/2018     12:41              0 5 = 9.12.16 Bankin Sirri 157.98.pdf
-A ----       10/06/2018     12:41              0 6 = 9.1.17 Bankin Sirri 123.45.pdf
nan, da filename ƙunshi serial # a farkon, bi ta =, bi da 'Bank Sirri’ bi da karshen bayani balance.
Wadannan fayiloli ne a gaskiya Credit Card MAGANGANU da kalmar 'Bank’ bukatar da za a maye gurbinsu da kalmomi 'Credit Card'. All sauran filename kamata zama guda.
Domin cimma wannan, we will be using Windows PowerShell with Regex.
Don lissafa duk banki kalamai, mu yi amfani da ls umurnin, sa'an nan bututu da fitarwa
LS | Ren -newname {$_.name -replace('(.+)Bankin(.+)','$ 1Credit Katin $ 2')}
The Sake suna umurni da aka yi amfani da bayan bututu zuwa sake suna da fayiloli. $_ ne abu da cewa riko da fitarwa kafin bututu, kuma muna amfani da sunan dukiya da $_ abu. -replace is used on strings in PowerShell, wanda ya maye gurbin wani layi da wani sabon kirtani. -replace ne mai aiki da daukan 2 sigogi. 1st siga ne tsohon kirtani cewa muna so mu maye gurbin da 2nd siga ne sabon kirtani.
Kamawa kungiyoyin a Regex yale mu mu ci gaba sassa na kirtani. a Regex, wani abu ya sa a cikin zance ne kama amfani da daga baya. misali. (.+)Bank(.+) kama wani abu kafin da kuma bayan da haruffa 'Bank'. Za mu iya yin amfani da wadannan kama sassa, da yin amfani da $ kuma da dama. 1st zance na kama a cikin $1 da 2nd zance na kama a cikin $2 da dai sauransu…
A cikin 1st siga, mu saka da haihuwa kirtani cewa muna so mu canza, kuma a lokaci guda muna kama da sassa na kirtani cewa muna so mu ci gaba da (kama). A 2nd siga, sabon kirtani amfani da kama sassa cewa muna so mu ci gaba da, kazalika da sabon kirtani kanta misali. '$1Credit Card$2'.
Mode LastWrite Lokaci Length Name
-wani ----     10/06/2018     12:40              0 1 = 9.8.16 Credit Card Sirri 298.67.pdf
-A ----     10/06/2018     12:40              0 2 = 9.9.16 Credit Card Sirri 134.74.pdf
-A ----     10/06/2018     12:41              0 3 = 9.10.16 Credit Card Sirri 123.43.pdf -A ----     10/06/2018     12:41              0 4 = 9.11.16 Credit Card Sirri 134.54.pdf -A ----     10/06/2018     12:41              0 5 = 9.12.16 Credit Card Sirri 157.98.pdf -A ----     10/06/2018     12:41              0 6 = 9.1.17 Credit Card Sirri 123.45.pdf
← Yadda za a gyara Google Play Services ya tsaya matsala a jinsi OS 15.1? Yadda za a kafa iptables don mayar atomatik a kan sake yi a CentOS Linux? →