Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. Recursively Replace Text in Files

Recursively Replace Text in Files

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
linuxtutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Grahamfff
    wrote on last edited by
    #1

    I need to replace text in all text files in the directory (including sub-directoies). I have managed to get the following working, but dont know how to combine them!

    find . -exec grep –n "oldText" '{}' \; -print

    find . -type f -name '*.read' -print -exec sed s/oldText/newText/g '{}' \;

    ANy suggestion please, I have done searches, but just want a simple one line command if possible. Regards, Andy.

    grahamfff

    R 1 Reply Last reply
    0
    • G Grahamfff

      I need to replace text in all text files in the directory (including sub-directoies). I have managed to get the following working, but dont know how to combine them!

      find . -exec grep –n "oldText" '{}' \; -print

      find . -type f -name '*.read' -print -exec sed s/oldText/newText/g '{}' \;

      ANy suggestion please, I have done searches, but just want a simple one line command if possible. Regards, Andy.

      grahamfff

      R Offline
      R Offline
      RomanMzh
      wrote on last edited by
      #2

      Using Perl perl -pi -w -e 's/oldString/newString/g;' [place]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups