Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] Zastepowanie ciagu znakow
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Polskie forum (Polish) Polish OTW
View previous topic :: View next topic  
Author Message
soban_
l33t
l33t


Joined: 27 Aug 2008
Posts: 668
Location: /home/soban

PostPosted: Mon Nov 14, 2011 4:13 pm    Post subject: [SOLVED] Zastepowanie ciagu znakow Reply with quote

Dosyc fajnym sposobem na wyszukanie ciagu znakow w danym folderze i podfolderach jest:
Code:
find . -name "*" -exec grep -H 'Edit this entry.' {} \;
./wp-content/themes/GamezMag/page.php:          <?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
./wp-content/themes/GamezMagBEZKOLUMN/page.php:         <?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
./wp-content/themes/pixel2/page.php:<br/><small><?php edit_post_link('Edit this entry?','',''); ?></small>
./wp-content/themes/pixel2/page_fullwidth.php:<br/><small><?php edit_post_link('Edit this entry?','',''); ?></small>
./wp-content/themes/pixel2/single.php:<br/><small><?php edit_post_link('Edit this entry?','',''); ?></small>
./wp-content/themes/pixel/page.php:<br/><small><?php edit_post_link('Edit this entry?','',''); ?></small>
Jednak trzeba recznie wchodzic i edytowac te wpisy. Czy istnieje jakis szybki sposob na zamiane danego ciagu znakow na inny, zamiast edytkowac kazdy plik recznie? (Fajnie jeszcze jesli pokazywalby sciezke do pliku i pytal sie czy zastapic to w taki sposob - w jaki sposob bedzie linijka wygladac po edycji, bo wiadomo nie zawsze to moze byc dobre.)
_________________
gg: 525600


Last edited by soban_ on Thu Feb 28, 2013 9:04 am; edited 1 time in total
Back to top
View user's profile Send private message
joi_
Apprentice
Apprentice


Joined: 28 Mar 2005
Posts: 171

PostPosted: Mon Nov 14, 2011 6:08 pm    Post subject: Reply with quote

Code:
perl -pi -e 's/xxx/yyy/g' plik
Back to top
View user's profile Send private message
SlashBeast
Retired Dev
Retired Dev


Joined: 23 May 2006
Posts: 2922

PostPosted: Mon Nov 14, 2011 6:13 pm    Post subject: Reply with quote

po co find jak grep ma przelacznik -r? Mozesz zrobic, by grep zwracal tylko pliki zawierajace i uzyc seda z -i do zmiany.
Back to top
View user's profile Send private message
sebas86
Guru
Guru


Joined: 01 May 2005
Posts: 568
Location: Szczecinek / Szczecin

PostPosted: Mon Nov 14, 2011 7:20 pm    Post subject: Reply with quote

Z findem można jeszcze odfiltrować po nazwie.

Code:
find . -name "*" -exec sed {} 's/Edit this entry/dupa/' > /tmp/tmp.txt \; -exec mv /tmp/tmp.txt {} \;

_________________
Nieważne jaka dystrybucja, ważne, że Linux!
Back to top
View user's profile Send private message
soban_
l33t
l33t


Joined: 27 Aug 2008
Posts: 668
Location: /home/soban

PostPosted: Wed Feb 27, 2013 2:28 pm    Post subject: Reply with quote

Jakby komus byla potrzebna wersja, ktora szuka bez binarek to:
Code:
x=`find . -type f -exec grep -q "slowo_szukane" '{}' \; -print |  xargs file | grep ASCII | cut -d: -f1 | xargs` && sed -i 's//slowo_zastepowane/' $x
jak ktos ma ochote i czas to moze to ladniej napisac d-: mam tylko pytanko jesli sa takie 3 "stringi" w jednym pliku to musze wywolac ta linijke 3x, czy jest jakis szybszy myk zeby sed zrobil to dla calego pliku, a nie tylko dla jednego "stringa" w danym pliku?

//edit troche lepsza wersja (bez binarek):
Code:
x=`grep -R slowo_szukane * | grep -o "^.*\:" | sed "s/://g" | xargs` && sed -i 's/slowo_szukane/slowo_zastepowane/' $x
Z tym stringiem to chodzi mi o cos takiego (cat /etc/hosts):
Quote:
10.1X0.X6.4X3 slowo_szukane slowo_szukane.varible slowo_szukane.varible
aby zastapiac kazdy z tych znakow musze wywolac skrypt 3x. Da rade jakos 'lepiej' potraktowac sedem?
_________________
gg: 525600
Back to top
View user's profile Send private message
sebas86
Guru
Guru


Joined: 01 May 2005
Posts: 568
Location: Szczecinek / Szczecin

PostPosted: Wed Feb 27, 2013 6:24 pm    Post subject: Reply with quote

Quote:
x=`grep -R slowo_szukane * | grep -o "^.*\:" | sed "s/://g" | xargs` && sed -i 's/slowo_szukane/slowo_zastepowane/g' $x
Magiczne g we wskazanym miejscu nie rozwiązuje problemu?
_________________
Nieważne jaka dystrybucja, ważne, że Linux!
Back to top
View user's profile Send private message
soban_
l33t
l33t


Joined: 27 Aug 2008
Posts: 668
Location: /home/soban

PostPosted: Thu Feb 28, 2013 9:04 am    Post subject: Reply with quote

Pomoglo, dziekuje - solved.
_________________
gg: 525600
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Polskie forum (Polish) Polish OTW All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum