Show 4 more comments. You could even do it like this: Example grep -rl 'windows'. Matthias Braun The grep is only useful if there are files which should not be modified. Running sed on all files will update the file's modification date but leave the contents unchanged if there are no matches. When using -i , I believe sed changes the file time of every file it touches, even though the contents are unchanged. This command needs a "" after the -i to denote that no backup files will be made after the in-place substitution takes place, at least in macosx.
Check the man page for details. If you want a backup, this is where you put the extension of the file to be created. For spaces is file names you need to do NULL termination on grep and xargs.
I love the funny subtle subliminal command to replace Windows with Linux — Kostrahb. This works best for me on OS X: grep -r -l 'searchtext'. Marc Juchli Marc Juchli 2, 22 22 silver badges 19 19 bronze badges. Why is the sort -u even part of this? In what circumstances would you expect grep -rl to produce the same file name twice? I think this is probably the easiest method on here to get the job done. Forcing grep when it is not needed is unnecessary.
Walf Walf 7, 2 2 gold badges 37 37 silver badges 54 54 bronze badges. Perl itself is quite capable of recursing a file structure. In fact, there is a tool find2perl which ships with Perl which does this sort of thing without any xargs trickery. This is a nice solution for Windows, as it avoids the sed-based solutions' issue of converting the line endings. Another option would be to just use perl with globstar. GuiltyDolphin GuiltyDolphin 1 1 gold badge 7 7 silver badges 10 10 bronze badges.
That's why I am specifically looking for grep and sed. The Overflow Blog. Podcast Making Agile work for data science. As seen in previous example, rg will search and replace all occurrences. So, you'll have to be creative with regexp to replace only a specific occurrence per input line.
If you have moreutils installed , then you could use sponge as well. By default, rg uses Rust regular expressions, which is much more featured compared to GNU sed. Connect and share knowledge within a single location that is structured and easy to search. If you're matching a substring of the whole line, you can either use sed's s command with a regex to mop up the rest of the line:.
You can use inplace functionnality of sed :. Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Learn more. Grep: search and replace full line Ask Question.
Asked 9 years, 10 months ago. Active 4 years, 7 months ago. Viewed 34k times.
0コメント