Hello Guest
* *
Welcome, Guest. Please login or register.
2017-10-20, 03:30

Login with username, password and session length

Author Topic: [Bash] Recursively replace a string in multiple files in multiple directories!  (Read 10338 times)

0 Members and 1 Guest are viewing this topic.

Offline Marook

  • Administrator
  • Newbie
  • *****
  • Posts: 25
    • View Profile
If you need to replace a special string in multiple files in multiple directories, you won't find a recursive option in sed. So must combine grep in combination with xargs and finally sed for the replacement. The following one-liner should do the trick :

Code: [Select]
grep -ilr ‘old-string’ * | xargs -i@ sed -i ‘s/old-string/new-string/g’ @

where old-string = string which needs to be replaced
an new-string = new string which replace old-string
« Last Edit: 2012-11-05, 11:09 by Marook »

 

Recent

Members
  • Total Members: 1
  • Latest: Marook
Stats
  • Total Posts: 34
  • Total Topics: 34
  • Online Today: 3
  • Online Ever: 82
  • (2013-05-08, 10:46)
Users Online
Users: 0
Guests: 3
Total: 4
Google