Tagged Questions
1
vote
2answers
37 views
Search and replace full line in recursive files
I'm using:
grep -n -H -o -R -e textword .
List all file recursively under directory '.' with string 'textword' and show the file, line and only portion matching.
I need to remove lines that ...
4
votes
3answers
313 views
How to replace current word under cursor in Emacs
How do I replace current word under cursor in Emacs?
I know that I can use query-replace or replace-string but every time I do so I have to type entire string to be replaced, this is just annoying.
...
4
votes
3answers
111 views
Smart way to perform a similar replacement (not simple enough for diff) in multiple files?
I have a bunch of files (45, so too many to edit them manually without going crazy) which all require the same changes (as seen in the three diffs at the end of this question).
Most tools used for ...
3
votes
1answer
1k views
How to do multiline search and replace text (delete) recursively
I want to go recursively through a directory and search for specific content in all files. The content should then be replaced if found. With a single line I would make something like this:
find . ...
2
votes
2answers
247 views
remove only specific text occurrences from string using sed
I have a text file that contains many rows of this sort of thing:
/*[17:51:27][1 ms]*/ UPDATE `country` SET `region_id` = '4' WHERE `country_id` = '36';
Is there a way that I can use sed to remove ...
5
votes
1answer
289 views
Conditional search and replace on a line in vim?
Let' say I want to comment and uncomment a line.
I know I can
:s!^!//!
and then
:s!^//!!
Now what if I want this as an one-liner?
Basically, if a line starts with // then remove it, else add ...
5
votes
4answers
1k views
Vim :s replace first N < g occurrences on a line
In vim, I sometimes have occasion to replace the first few occurrences of a match on a line, but not every one like g would. e.g.:
a a a a a
to
b b b a a
I know I could use ...
7
votes
1answer
187 views
Case-preserving search and replace in vim?
In vim, I know I can search with or without case sensitivity. But if I want to search for a string in either upper or lower case, and replace it with a replacement of the same case, is that possible ...
3
votes
5answers
604 views
How to replace a list of placeholders in a text file?
I have a text (configuration) file, but the program that reads the file unfortunately doesn't allow using any kind of variables. So I'd like to use a preprocessor that replaces a set of placeholders ...