Linux: How do I mass find and replace text in files under linux using perl?

Few friends have asked me how to do mass find and replace text in files under linux. There are quite a bit of options in linux to achieve mass replacing of text in files. If you are doing it file by file, you can achieve that in vi by opening, running replace and closing and going to next file. But sometimes that can be very tedious and you would rather do mass replacement on all files containing certain extension. We can do this by using sed or perl. Since most people are familiar with perl (at least most system admins and programmers), I will show you a perl way of doing it which you can use with sed as well if you wish. First step is to get perl to do what we want on one file

perl -w -i -p -e "s/search_text/replace_text/g" filename

-w turns warnings on
-i makes Perl operate on files in-place (if you would like to make backups, use -i.bak, this will save filename.bak files)
-p loops over the whole input
-e specifies Perl expression
filename works on one file at a time

Once we get the results we want, we can now pass it multiple files by doing something like:

perl -w -i -p -e "s/search_text/replace_text/g" *.php

This will search and replace within all php files in the directory you are in.

Now, let us say you want to go through your whole web directory and replace every place where you have “Perl is good” to “Perl is great”, you would use following command:

find /www_root -name "*.php"|xargs perl -w -i -p -e "s/Perl is good/perl is great/g"

find will start at /www_root, look for filenames which have .php extension, xargs takes that filename and passes it to perl as an arguement.

DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. Use at your own risk.

408 thoughts on “Linux: How do I mass find and replace text in files under linux using perl?

  1. Cubase 7.5 Crack Key

    Designed for professionals from the ground up, Cubase 7.5 Crack Key four sets a new
    commonplace for built-in music manufacturing software program
    by combining powerful audio and MIDI recording, synthesis, editing, mixing and
    effects. We ended up with so much music that we had a good amount to choose
    from to make Sounds That Can’t Be Made a strong album.
    New features and enhancements include an advanced
    multi-track editing tool, a new take-comping system and VST Expression 2.

  2. Menggunakan Hijab

    Hallo all hijabers se Indonesia,,,, Kali ini saya akan memberikan satu video yang sangat menarik tentang Mengenakan Jilbab.
    — Klo enggak percaya, coba tonton deh di Pasti kamu akan suka dech.

    Btw, jangan lupa berlangganan dan comment yaa….. — Oh iya, kalo kalian suka dengan video
    tentang Mengenakan Hijab, Belajar Memakai Jilbab, Video Jilbab Tutorial,
    Video Tutorial Hijab, Video Memakai Hijab, Video Tutorial Hijab, Video Hijab, jangan lupa simak channel
    kami ini terus yaaa….. Makasih

  3. izanagi samurai ninja online cheats

    In accession there is aswell an accomplishmet arrangement that offers some absolutely difficult
    achievements and some others that are just fun to do, such as lighting ann adversay on blaze
    as a pyro and achievement they jukp into the water.
    Sinxe then I’ve become even more fasciated by ninja lore and
    history. You caan try our hands at the advanced tutorial a few times.

  4. cmarvelfuturefighthack website

    I took another step and again I was looking up at the slates.
    As is the case in traditional lotteries, larger
    payouts wouldn’t require a guaranteed winner per drawing.
    Nowadays however thrre are many innovative types of
    epoxy coatings and specialized paints available to combat corrosion attack.

  5. Clash of Clan Hacks

    After this, you will be charged substantial interest in your remaining negative
    balance or perhaps in certain instances a set daily fee so
    you’ll need to make sure you’ve paid the debt within the 0% period Clash of Clan Hacks furthermore, previously many a dubious situations
    arose when the ceo took on large debts to keep a position inside the company’s shares– bernie ebbers
    of worldcom fame involves mind– never mind a $1.

  6. faire pousser la barbe rapidement

    How you are feeling is your asking from the Universe. However, during this
    kind of addiction, we have lost our sense of control.

    We will help you in anyway possible, but before emailing in your query, have
    a quick look at our FAQ page in case your question has already been answered.

  7. Bridgett

    Fantastic g?ods f?om you, man. ? have
    understand you? stuff ?revious to and y?u’re
    just t?o fantastic. I ?eally li?e what yo?’?e acquired here, certainly lik? wh?t you are ?aying and the way in which yo? say it.
    You mak? it enjoyable ?nd ?ou still care f?r to kee? it smart.

    I can not wait t? read much more f?om y?u. ?hi?
    i? actuall? ? great web site.


    What i do not realize is in reality ?ow you are no longer actually m?ch
    mor? smartly-liked than you may be now. You are so intelligent.
    Yoou re?o?nize therefore significantly ?n terms ?f thi? subject, made me in my opinioln consider it from numer?us v?ri?d angles.

    Its like women and men don’t seem to? ?be fas??nated except it’s something
    t? accompli?h with Girl gag?! Your personal stuff? nice.
    All the time take care of it up!

    my websit? … medical sales jo?s nashville tn (


    What i do not realize is in reality ?ow you are no longer actually m?ch
    mor? smartly-liked than you may be now. You are so intelligent.
    Yoou re?o?nize therefore significantly ?n terms ?f thi? subject, made me in my opinioln consider it from numer?us v?ri?d angles.

    Its like women and men don’t seem to? ?be fas??nated except it’s something
    t? accompli?h with Girl gag?! Your personal stuff? nice.
    All the time take care of it up!

    my websit? … medical sales jo?s nashville tn (

  10. cmarvelfuturefighthack website

    Using a specific military strategy, known as “Preemptive Strike,” anyone can develop a future that others will
    marvel at and one that establishes a legacy too be rememberedd and
    emulated. Has technology reached such a stae as now to replace employees.
    And he required all the earth and those who belong to this world
    to worship the first beast, whose death-wound had been healed.


    I do consider all of the ideas you have presented for
    your post. They are really convincing and will certainly
    work. Still, the posts are too quick for starters.
    Could you please lengthen them a bit from next time? Thank you for the post.

  12. cubic castles youtube

    Otto the Ghost, who appears at Halloween, is well-known to Hicks’ customers.

    Therefore, you can get capitalize on the over-talked about benefits to harvest massive
    income from it. It is really widespread knowledge that repeated braking from
    ultra-high speeds wreaks havoc on tradition iron brake rotors – they simply can’t dissipate the

  13. karaoke

    Many people who attempt to add captions to their films using
    this kind of software find more than a little difficulty in synchronising the text
    to the audio. This creates sexual polarity, which allows attraction to exist.
    After you have one of your own, you’ll love it and
    you’ll want to buy another one as soon as you can afford it.

  14. Oliva

    If the allergen is consumed, the allergic reaction may primarily
    occur in the mouth, stomach and intestines. When you trace a meridian you are
    simply running your hand along the path of that meridian on your body.
    Make sure that you keep your childs fingernails
    cut nice and short to discourage scratching the problem area.

  15. news

    (A broadband connection will deliver superior audio and video quality).
    At 5ft 9inches, Chicharito is not only lightening fast and has great
    control on and off the ball. FIFA Manager 10 features a surprisingly low minimum system specification, especially considering the much high requirements of the FIFA
    10 arcade soccer game.


    Organisations now realise that they can improve
    bboth the performance and motivation of their associates through coaching.
    The second phase involves the explanation of EMDR treatment protocol aand theory.
    The R is for reality, checkig to explore the current situation.

  17. marketing programs

    My brother recommended I may like this web site.
    He used to be entirely right. This publish actually made my day.
    You cann’t consider just how so much time
    I had spent for this information! Thanks!

  18. kitchen appliance association

    It distributes heat evenly and faster all around the food item,
    ensuring a thorough and perfect cooking result. This type of a company
    will also have a detailed ordering system. In this business it’s all about showing leadership and
    outcome so you will never have to hassle
    your friends, family and relatives again. We have seen kitchen appliances that are
    compact and colorful. Stay Indoors and be entertained – for free or low
    cost: Go to the mall and window shop, sit in comfy chairs
    and play with handheld games, socialize with your friends or read a book.

  19. adam

    I got this website from my pal who shared with me regarding this site
    and at the moment this time I am visiting this web page and reading very informative
    posts at this time.

  20. stonemasons mark

    Semolina gives a nice surface appearance of concrete, making it indelible and for sanding. For terrazzo can also add pigments. Due the high cost, both as meal and pigments, terrazzo delivers the outer layer is element thickness stonemasons edinburgh of 2 to 3 cm and the backing are made from ordinary concrete or mortar cement. a) b) c) Fig. 1. Examples of masonry works: a) tops, b) wall and stairs [], c) fireplaces [Http://] Concrete has a significant compressive strength but low tensile strength. Therefore bending elements strengthens the tension zone, using reinforcing steel, which It is 200 times the tensile strength of the concrete. Reinforced concrete bars steel stonemasons edinburgh called reinforced concrete. Proper cooperation of concrete and steel is ensured by: – Good adhesion to steel concrete, so that the load acting on the concrete are transmitted by friction between the two materials for steel, – Similar thermal expansion of the two materials. – Protection of the rebar in reinforced concrete element by enveloping them concrete,

  21. Masonry

    The harmfulness of landfill waste on the environment depends on many factors, and in particular the characteristics of the waste (physical, chemical, biological), the quality of soil, land use, the environment adjacent to the landfill and its operation, as well as a method of rehabilitating and target land landfill. About nuisance for the environment and difficulties in the operation of the landfill is with the criteria hydrogeological and geotechnical meet the applicable technical requirements and are properly exploited. largely governed by the properties of the selected place. There are downhole location (pits, ravines, gorges), the slope (fragments ravines, hollows or embankments) and flat (need elevation solid landfill over the surrounding area). Landfills can also be divided into nadpoziomowe (located on the flat), sublevel (resulting from depressions) and lateral (based on the slope).

    In Poland, there are three types of landfills:

    Fugitive – occupy pits or natural depressions, with no special preparation. The result of this landfill is among groundwater contamination, uncontrolled emission of gases into the atmosphere and the excessive growth of birds and rodents.
    Half-organized – the construction of such landfills in recent years has taken quite often. From the previous type of landfill distinguishes them to insulate landfilled waste from the ground. However, this process also does not protect the environment from the emission of leachate and odors and dust. It is a transitional form in the pursuit of proper equipment and operation of landfills.
    Organized – they have a special location stonemasons edinburgh with the criteria hydrogeological and geotechnical meet the applicable technical requirements and are properly exploited.
    In Poland, there are three types of landfill (pursuant to art. 103, section 2 of the Act of 14 December 2012 on waste, Dz.U.2013, poz.21):

    landfill for hazardous waste
    landfill for inert waste
    landfill for non-hazardous and inert (this group includes municipal waste landfill)

  22. Lula

    Supply a contributed container or other container for main storage and take into consideration buying any
    missing products for them to guarantee that their set is effectively equipped.

    my blog post hurricane preparedness kit texas, Lula,

  23. Starr

    ricreare la foto è molto semplice: ora che fa freddo, entrate dentro la piscina della palestra con gli ocilcahi…ecco fattoprovate con una macchina fotografica e vedete :)oppure in montagna state fuori di sera per un po’, poi rientrate in casa e provate a scattare qualche foto…

  24. jordan shoes

    My spouse and i were so fulfilled that Michael managed to round up his survey with the precious recommendations he discovered through the web pages. It is now and again perplexing to simply possibly be giving out helpful hints which often some others may have been making money from. So we do know we’ve got you to give thanks to because of that. The main illustrations you’ve made, the simple site menu, the relationships your site make it easier to engender – it’s mostly impressive, and it is leading our son and us consider that this content is exciting, which is certainly highly important. Thank you for the whole lot!

  25. dior sunglasses

    I precisely wanted to appreciate you once again. I do not know the things that I would’ve used in the absence of the actual smart ideas shared by you directly on such theme. It truly was a real frightful dilemma in my circumstances, however , viewing this skilled style you resolved that made me to leap with delight. Now i am grateful for your guidance and thus expect you realize what an amazing job you are always doing training most people with the aid of your website. Most probably you haven’t got to know any of us.

  26. pandora bracelet

    I simply wished to say thanks yet again. I do not know the things that I would have created in the absence of the tips shown by you over that question. It absolutely was an absolute hard concern in my circumstances, but observing your specialised strategy you dealt with that made me to leap over delight. I’m just happy for the work as well as hope you are aware of a great job you are getting into instructing the mediocre ones by way of your site. More than likely you have never met any of us.

  27. hermes belt

    I simply desired to appreciate you once again. I do not know the things I might have followed without the entire tips discussed by you on this field. It had been a very difficult setting in my opinion, however , viewing the expert approach you managed the issue made me to leap over contentment. I’m just happier for this assistance and then hope that you find out what a powerful job you were doing instructing men and women using your web blog. I know that you have never come across any of us.

  28. fenty puma

    I’m also commenting to make you know what a nice encounter our girl went through visiting yuor web blog. She even learned too many pieces, which included how it is like to have a marvelous helping style to make other people very easily learn about several impossible issues. You truly surpassed visitors’ expected results. Thanks for imparting these productive, dependable, edifying and even easy tips on the topic to Kate.

  29. minecraft

    you are truly a good webmaster. The site loading speed is incredible.
    It seems that you’re doing any distinctive trick.
    In addition, The contents are masterwork. you have done a magnificent
    activity on this topic!

  30. Johne1

    you are in point of fact a just right webmaster. The site loading velocity is amazing. It sort of feels that you are doing any distinctive trick. Furthermore, The contents are masterpiece. you’ve performed a magnificent process in this subject! eeebedddbdec

  31. BestGenia

    I have noticed you don’t monetize, don’t waste your traffic, you can earn extra
    cash every month with new monetization method. This is the best adsense alternative for any type of website (they
    approve all websites), for more details simply search in gooogle: murgrabia’s

  32. chamsua

    I have seen a lot of interesting things on your site, and it helped me gain more knowledge
    Share with you about our website, it also has a lot of useful things you need: Knowledge of infant and child care. Please visit my page and give me your review.

Leave a Reply

Your email address will not be published. Required fields are marked *