عندما يعمل أنت على [لينوإكس] [كمّند لين] وأنت تتصادف مبرد كبيرة أو [ا لرج نومبر وف] مبارد في أيّ أنت تحتاج أن يستبدل نص مؤكّدة مع آخر, يجد ويلصق على كلّ مثال من النص يستطيع كنت لقمة مستغرق وقتا طويلا. أقلقت جيّدا, [نو مور]. [لينوإكس] يتلقّى فقط الحل ل أنت. هنا طريق أن يجد واستبدلت خيط النص في [أن ور موش] مبارد تلقائيّا.
[سد] لغرض هذا تمرين عمليّ نحن سنستعمل [لينوإكس] [كمّند لين] أداة يدعى "". ? " [سد]" جدّا قوّيّة وأداة متعدّد استعمال, وكثيرا يستطيع كنت كتبت حول إمكانياته. نحن نستعمل مظهر محدودة جدّا من "[سد]" هنا. أنا بالتّأكيد أوصيت أنّ يقرأ أنت فوق قليلا أكثر على "[سد]" إن أنت تجد هذا مظهر من هو يهمّ.
نحن نذهب أن يستعمل الإعراب تالي أن يجد واستبدلت خيط النص في مبرد:
# [سد] - أنا' [س/] [[أريجنلتإكست]]/[[نوتإكست]]/' filename.txt
رأي يتلقّى أنت مبرد يدعى "[دتبس.تإكست]" مع يتعدّد مثل من ال [إيب دّرسّ] من ك قاعدة معطيات نادلة في هو. يحوّل أنت يتلقّى فقط إلى جديدة قاعدة معطيات نادلة ويحتاج أن يحدّث هو مع النادلة جديدة [إيب دّرسّ]. ال [إيب دّرسّ] قديمة 192.168.1.16 وال [نو ون] 192.168.1.22. هنا كيف أنت تذهب حول هو:
# قطة database.txt
[لوكلدتبس]=192.168.1.16
[لوكلدير]=/home/calvin/
[بروددب]=192.168.1.16
#?[سد] - أنا' [س/] 192.168.1.16/192.168.1.22 [/غ]'? [دتبس.تإكست]
[ك]في database.txt
[لوكلدتبس]=192.168.1.22
[لوكلدير]=/home/calvin/
[بروددب]=192.168.1.22
الآن فتحت المبرد "[دتبس.ينك]" وفحصت أن يرى إن ال [إيب دّرسّ] جديدة قد تمّ من ك قديمة واحدة. هنا التحطم من الأمر آنفة. أولى يدعو أنت ال "[سد]" أمر. بعد ذلك يمرّ أنت هو المعلمة "- [س]" أيّ يقف ل "[إين بلس وف]". الآن يستعمل نحن [ا ليتّل بيت] من تعبيرات نظاميّة, عادة يعرف بما أنّ "[رجإكس]"? لللقمة تالية. ال "[س]" في ال [قووت سترينغ] حامل قفص ل "بديل", وال "[غ]" في النهاية حامل قفص ل "شاملة". بين هم ينتج هم في "إبدال شاملة من ال الخيط النص أنت تضع [إين-بتوين] هم.
أنت يستطيع إختياريّا تخطّيت ال "[غ]" في النهاية. هذا يعني أنّ لن [ب] الإبدال شاملة, أيّ عمليّا يترجم إلى الإبدال من فقط المثال أولى من الخيط في خطّ. هكذا إن أنت تلقّيت خطّ مع يتعدّد مثل من النص أنت يكون تحاول أن يستبدل, هنا ماذا سيحدث
# cat database.txt
LOCAL_DATABASE = 192.168.1.16
LOCAL_DIR = /home/calvin/
PROD_DB = 192.168.1.16, 192.168.1.16
#?sed -i ’s/192.168.1.16/192.168.1.22/’?database.txt
# cat database.txt
LOCAL_DATABASE = 192.168.1.22
LOCAL_DIR = /home/calvin/
PROD_DB = 192.168.1.22, 192.168.1.16
Here comes the real magic. Now, say you want to change a string of text not just in a single file, but in the entire directory you are in. There are a number of text files in which you need to find and replace the “wine” with “champagne”.
# find . -maxdepth 1 -name “*.txt” -type f -exec sed -i ’s/wine/champagne/’ {} \
We use the find command to get a list of all the text files in the current directory. That’s the “find . -maxdepth 1 -name “*.txt” -type f” part. “find .?maxdepth 1″ tell the computer to look in the current directory and go no deeper than the current directory. The ‘-name??”*.txt”‘ part tells find to only list files with the extension of “.txt”. Then the “-type f” section specifies that “find” should only pick exactly matching files. Finally the “-exec” part tells “find” to execute the command that follows, which, in this case, is the “sed” command to replace the text - “sed -i ’s/wine/champagne/’ {} \”.
I?realize?that the above command seems complicated. However, once you use it a little bit you will realize that it is probably worth noting it down and using it. Now try changing a string of text in multiple levels of directories.





























{ 3 comments… read them below or add one }
> Then you pass it the parameter ?-s? which stands for ?in place of?.
I think it must be ?-i?
Now open the file ?database.inc? and check to see if the new IP address has taken place of your old one.
database.inc here I think it should be database.txt
Eso es muy facil….
pero por ejemplo como harias lo siguiente
tienes una ruta windows en un codigo y quieres pasarla a ruta de tipo linux
la cadena que buscas es C:\ejemplos\archivos\aqui
Cambiarla a /ejemplos/archivos/aqui
para un grupo de archivos que se encuentran en la misma carpeta…
Leave a Comment