Multiple find and replace of content using Grep º¹ÇÕ Ã£¾Æ¾ß ¹× ÄÜÅÙÃ÷ÀÇ »ç¿ëÀ» ´ëü grep

Posted on December 3, 2008 at 5:35 am 12 ¿ù 3 ÀÏ, 2008 °Ô½ÃµÊ ¿ÀÀü 5:34

We have posted articles about searching for files and file content using ¿ì¸®°¡ ÆÄÀÏÀ» °Ë»ö ¹× ÄÜÅÙÃ÷ ÆÄÀÏÀ» »ç¿ëÇÏ´Â ¹æ¹ý¿¡ ´ëÇÑ ±â»ç¸¦ °Ô½ÃÇÑ Super Finder ½´ÆÛ ¹è³¶ ¿©Çà and ¹× Google Desktop Google µ¥½ºÅ©Åé .  But what if you have a bunch of files wherein you want to actually replace a content inside them? .ÇÏÁö¸¸ ¸¸¾à ´ç½ÅÀÌ ½ÇÁ¦·Î ´ç½ÅÀÌ ¾î¶² Á¡¿¡¼­ ±×µé ³»ºÎÀÇ ÄÜÅÙÃ÷·Î ±³Ã¼ÇÏ·Á´Â ÆÄÀÏÀÇ ¹«¸®°¡? sure you can use Notepad or any text editor to find and replace content for individual files but this will require you to do this on each of the files. È®½ÇÈ÷ ´ç½ÅÀ» ã¾Æ ¸Þ¸ðÀåÀ̳ª ´Ù¸¥ ÅØ½ºÆ® ÆíÁý±â¸¦ »ç¿ëÇÒ ¼ö ÀÖÀ¸¸ç °³º° ÆÄÀÏ¿¡ ´ëÇÑ ÄÜÅÙÃ÷¸¦ ´ëüÇÒ ±×·¯³ª À̰ÍÀº ´ç½ÅÀÌ ÇÒ °¢°¢ÀÇ ÆÄÀÏÀÌ ÇÊ¿äÇÕ´Ï´Ù.

I have been using Integrated Development Environment (IDEs) tools like Netbeans and Visual Studio to do this for my software development projects but they are too ¡°bloated¡± for plain text files. (½Ê¿À) ³ÝºóÁî ¹× Visual Studio¿Í °°Àº µµ±¸¸¦ ³» ¼ÒÇÁÆ®¿þ¾î °³¹ß ÇÁ·ÎÁ§Æ®¸¦ À§ÇØÀÌ ÀÏÀ»ÇÏ´Â ÅëÇÕ °³¹ß ȯ°æÀ» »ç¿ëÇϰí ÀÖÁö¸¸ ±×µéµµ "ºñ´ëÇÑ"ÀÏ¹Ý ÅØ½ºÆ® ÆÄÀÏ¿¡ ´ëÇÑÀÖ½À´Ï´Ù.

With ¿Í ÇÔ²² winGrep winGrep , you can do a global search and replace of any string on all files located at your inputted path: ´ç½ÅÀº ±Û·Î¹ú °Ë»ö ÇÒ ¼öÀÖ´Â ¸ðµç ÆÄÀÏ¿¡ ÀÔ·ÂµÈ °æ·Î¿¡ À§Ä¡¿¡ÀÖ´Â ¹®ÀÚ¿­ÀÇ ±³Ã¼ :

Step 1 : In the ¡°Search in¡± field, enter the directory path. 1 ´Ü°è : ""Çʵ忡ÀÖ´Â µð·ºÅ丮 °æ·Î¸¦ ÀÔ·Â °Ë»öÇÕ´Ï´Ù.

Step 2 : In the ¡°Search for¡± field, enter the string or regular expression 2 ´Ü°è : ""Çʵ忡 ´ëÇÑ ¹®ÀÚ¿­À̳ª Á¤±Ô½ÄÀ» ÀÔ·Â °Ë»ö

Step 3 : Click ¡°Search¡± button 3 ´Ü°è : Ŭ¸¯ÇÏ¿© "°Ë»ö"¹öưÀ»

À̹ÌÁö

You should see the search results on the bottom part of the screen: ´ç½ÅÀº È­¸éÀÇ ÇÏ´Ü ºÎºÐ¿¡ ´ëÇÑ °Ë»ö °á°ú°¡ ³ªÅ¸³³´Ï´Ù :

À̹ÌÁö

The listing has a column with filename, size, matches inside the file, path and encoding type.  The ¡°matches¡± column tells you how many instances of the searched word exists in the file. ¸ñ·Ï, ÆÄÀϰú ¿­ÀÇ Å©±â¸¦ °¡Áø ÆÄÀÏÀÇ °æ·Î¿Í À¯ÇüÀ» ÀÎÄÚµùÀ» ¾ÈÀ¸·Î ÀÏÄ¡ÇÕ´Ï´Ù. ""¿­¿¡ ÀÏÄ¡ÀÇ ÀνºÅϽº°¡ ´ç½Å¿¡°Ô ¾ó¸¶³ª ¸¹Àº ´Ü¾î¸¦ °Ë»öÇÑ ÆÄÀÏ¿¡ Á¸ÀçÇÕ´Ï´Ù.

To do a search and replace, enter the replacement word in the ¡°Replace with:¡± field then click ¡°Replace¡±: °Ë»öÀ» ¼öÇàÇÏ·Á¸é ´ëü, "¹Ù²Ù±â¿¡ ÇÔ²² ´ëü ´Ü¾î¸¦ ÀÔ·Â :"Çʵ带 ´©¸¥ ´ÙÀ½ "¹Ù²Ù±â":

À̹ÌÁö

Be careful as this can ruin your files.  I usually backup my files before doing a search and replace since a replace will effectively change the content of the files. ÀÌ °°Àº ÆÄÀÏÀ» ¸ÁÄ¥ ¼öÀÖ´Ù Á¶½ÉÇØ¶ó. ³­ ÁÖ·Î ¹é¾÷À» °Ë»öÇÏ°í ±×¸®°í È¿°úÀûÀ¸·Î ÆÄÀÏÀÇ ³»¿ëÀ» º¯°æÇϱâ Àü¿¡ ±³Ã¼ ÀÌÈÄ ³» ÆÄÀÏÀ» ´ëüÇÕ´Ï´Ù.

To create backup files, make sure to check the ¡°Create backup files¡± checkbox: , ""üũ : ¹é¾÷ ÆÄÀÏÀ» ¸¸µé°í ÀÖ´ÂÁö È®ÀÎÇÏ°í ¹é¾÷ ÆÄÀÏÀ» ¸¸µé·Á¸é

À̹ÌÁö

The backup files will be saved on the same folder with a ¡°.bak¡± extension.  This way you can ¡°recover¡± files by renaming the ¡°.bak¡± files. ¹é¾÷ ÆÄÀϰú µ¿ÀÏÇÑ Æú´õ¿¡ ". À̸í¹Ú"È®Àå¸íÀ¸·Î ÀúÀåµË´Ï´Ù. ´ç½Å "" "ÆÄÀÏÀº". bakÀÇ À̸§À» º¯°æÇÏ¿© ÆÄÀÏÀ» º¹±¸ÇÒ ¼öÀÖ´Â ¹æ¹ý.

If there are cases wherein you only want to make it search based on a filename pattern or file size, use the ¡°Limit Search¡± options: ¿©±â¼­ ´ç½ÅÀº ±×°ÍÀÌ °æ¿ì¿¡´Â ÆÄÀÏ À̸§ ÆÐÅÏÀ̳ª ÆÄÀÏ Å©±â¿¡, "Çѵµ °Ë»ö"À» ±â¹ÝÀ¸·Î °Ë»öÀ» ¸¸µé°í ½Í¾î ¿É¼ÇÀ» »ç¿ëÇÏ´Â °æ¿ì :

À̹ÌÁö

In the example above, I set it to search only for files with a .epj extension.  You can change this to any file name extension like .log or .txt. À§ÀÇ ¿¹¿¡¼­, ³»°¡ °¡Áø ÆÄÀϸ¸À» °Ë»öÇϵµ·Ï ¼³Á¤ÇÕ´Ï´Ù. epj È®Àå. ´ç½ÅÀÌ ¿øÇÏ´Â ÆÄÀÏ À̸§ È®Àå¸íÀ» º¯°æÇÒ ¼öÀÖ½À´Ï´Ù. ·Î±× ¶Ç´Â¸¦. txt.

winGrep, is a powerful tool.  Use it with caution because there is no ¡°undo¡± functionality.  Make sure to backup your critical files first before doing a replace.  You can get grepWin for free from the Google code website: winGrep, °­·ÂÇÑ µµ±¸ÀÔ´Ï´Ù. ½ÅÁßÈ÷ »ç¿ë ¾ø±â ¶§¹®¿¡ "Ãë¼Ò"±â´ÉÀÔ´Ï´Ù. ´ç½ÅÀÇ Áß¿äÇÑ ÆÄÀÏÀÌ ÀÖ´ÂÁö È®ÀÎÇϱâ Àü¿¡ ¸ÕÀú ¹é¾÷À» ´ëüÇϰíÀÖ´Ù. grepWin ¹«·á Google Äڵ带 À¥»çÀÌÆ®¿¡¼­ ¾òÀ» ¼öÀÖ´Ù :

http://code.google.com/p/grepwin/downloads/list

Ben Carigtan shows you how it¡¯s done. Carigtan º¥ ¾î¶»°ÔÇϸéµÇ´ÂÁö º¸¿©ÁÝ´Ï´Ù.

Enjoyed this post? ÀÌ °Ô½Ã¹°À» ÀßÇß³ª? Subscribe to Online Tech Tips via ¿Â¶óÀÎ Å×Å© ÆÁÀ» ÅëÇØ ±¸µ¶ ½Åû RSS Feed RSS Çǵå or via ¶Ç´Â¸¦ ÅëÇØ Email À̸ÞÀÏ and receive free daily productivity tips. ¹«·á ÀÏÀÏ »ý»ê¼º ÆÁÀ»¹ÞÀ» ¼öÀÖ´Ù.

» Filed Under »Ãâ¿ø¿¡¼­ Computer Tips ÄÄÇ»ÅÍ ÆÁ

¸ÀÀִ¿¡ Ãß°¡ Save this page ÀÌ ÆäÀÌÁö¸¦ ÀúÀå ±×°Í Mixx Stir it up on Mixx Mixx¿¡ ¿Ã·Á ÆÄ¹®
reddit Add to Reddit reddit¿¡ Ãß°¡ StumbleUpon Stumble this page ÀÌ ÆäÀÌÁö¸¦ ´õµë´Ù

Related Posts °ü·Ã °Ô½Ã¹°

Please post your comments/suggestions! ±ÍÇÏÀÇ ÀǰßÀ» °Ô½ÃÇϽñ⠹ٶø´Ï´Ù / Á¦¾È!