The replace tag has no wiki summary.
4
votes
4answers
102 views
sed how to substitute when string has “http://” in it?
I have a file xx that has the following contents:
@base_url = "http://dmstaffing-stage.herokuapp.com/"
I want to use sed to eliminate this line (replace with nothing). I have used this sed ...
2
votes
3answers
73 views
Use sed to find whole word and replace
I have the following block of text in a file:
test3.legacy test4.legacy test3 test3.kami
I only want to search for test3 as a whole and replace it with nothing. Unfortunately, all my attempts have ...
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 ...
0
votes
0answers
17 views
How to disable Dejavu sans at global level? And what font could be the substitute?
I'm fed up with one DejaVu Sans rendering bug, which I call "forever bug" (bug that gets it's problem somewhat negated or behavior changed between releases, but never fixed). I have problem with dot ...
2
votes
2answers
281 views
How can I replace text after a specific word using sed?
I have a file named .ignore. In need to replace the projdir. For example:
ignore \..*
ignore README
projdir Snake
I need to replace Snake with, for example, "PacMan". I read the man page, but I ...
4
votes
2answers
166 views
Why does this add spaces? echo “x ax” | sed 's/x\s*/x /'
I want to find a x, and replace the 0 or more following spaces (\s*) with just a single space.
echo "x ax" | sed 's/x\s*/x /'
For some reason, instead of replacing the spaces with the single space, ...
2
votes
1answer
128 views
How to fix networking driver boot load failure after replacing hardware?
After replacing the motherboard, which is the same as after replacing the network adapter interface hardware (NIC), our Debian 6.0.6 no longer loads the networking driver on boot.
The manual approach ...
-1
votes
1answer
42 views
Replace AAA for BBB in file
Given I have a file with several words, how can I do the following:
How can I replace AAA for BBB in a file with Unix?
3
votes
2answers
85 views
How to convert *text* to {\i text} with sed?
I would like to replace every occurrence of *text* into {\i text}.
text *text* text
*text* text *text*
*text text text* text
should become
text {\i text} text
{\i text} text {\i text}
{\i text ...
1
vote
5answers
207 views
Replacing lines in files with file contents
I have several files which contain some PHP includes and I want to substitute them with the file contents. The file looks like
foo
<?php
include("file1.php");
?>
bar
baz
<?php
...
2
votes
3answers
240 views
Substitute placeholders in template
Say I have a shell configuration file config like this:
HOST=localhost
PORT=8080
Now I have a template template like this:
The host is <%= @HOST %>
The port is <%= @PORT %>
How do I ...
2
votes
2answers
116 views
Copying hashtag comments recursively within <blocks>
I have two files, one with blocks like
<record>
line1
line2
line3
#model bla bla bla
</record>
while the other file has exactly the same number of blocks, but without the hashtag ...
2
votes
1answer
148 views
Replace semicolons to commas between the quotes only [duplicate]
Possible Duplicate:
Remove comma between the quotes only
I'm trying to use awk function to replace the semicolons between quotes to comma and it is 98% ok for me, because I want to keep the ...
6
votes
4answers
2k views
Remove line containing certain string and the following line
I use this
cat foo.txt | sed '/bar/d'
to remove lines containing the string 'bar' in the file.
I would like however to remove those lines and the line directly after it. Preferably in sed, awk or ...
1
vote
4answers
335 views
Replace text between brackets
I'm using awk '{ gsub(/BAR|WIBBLE/, "FOO"); print }' to replace text in data like:
SOMETHING [BAR, WIBBLE]
SOMETHING [BAR]
This gives the desired result of:
SOMETHING [FOO, FOO]
SOMETHING [FOO]
...
6
votes
2answers
283 views
shell script/utility replace 2 byte unicode in binary file
I have many large Unicode files. I would like to replace each Unicode byte pair with a new Unicode byte pair. For example, the original file contains
"C3 B9 C3 AB C3 B8 C3 B0"
and I would like to ...
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 ...
2
votes
2answers
137 views
Add info under specific line
I want to know how could I add files contain information under specific line in file.
For example, I have file1.txt with the following lines:
line 1
line 2
line 3
and file2.txt has the ...
4
votes
1answer
162 views
Emacs simple arithmetics in query replace
Is it possible to do the following in emacs:
Query replace all numbers in a region by the number +n, for example if you have:
12 and 7 are nice numbers
let n be 3, then it should transform to
15 ...
1
vote
2answers
256 views
How to find and replace files contents that match a pattern?
Suppose we have a folder named Project.
I would like find each file in the folder that contains the pattern &$
at the function call.
For example should replace:
AnyFunction(&$arg);
with
...
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
3answers
3k views
Sed : Replace pattern on every second occurence?
Is there a way to tell sed to replace the pattern on every second occurrence? Or at least on every second line? (Sure it's possible with a script, but I was asking myself if sed can do it to).
...
6
votes
4answers
116 views
Replace a line with the line that I have in the buffer in vi
I cc or dd to copy a line into my paste buffer. Then I go to a new location.
I want to replace a line that I see. So I type p Down dd.
Is there an easier way (fewer keystrokes)?
2
votes
2answers
246 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 ...
2
votes
1answer
184 views
Duplicate selected words with sed and replace it
I have to modify a document containing xml data; one modification I couldn't set up with sed.
I have to modify the following expressions from:
<Bild ...
3
votes
2answers
210 views
When merging directories with similarly-named files, how do you ensure that only smaller+earlier files are replaced?
E.g., if you want to merge two directories with each other (by moving everything from directory 1 into directory 2), and both directory 1 and directory 2 have some files with the same name.
Then how ...
0
votes
1answer
2k views
Replacing one test string with another in particular column
I would like to replace "CC" with "C" and "AA" with A" in a particular column of Tab delimited file (using awk probably).
1
vote
2answers
181 views
How to split vCards lines
Related to How to join vCards lines, vCard does a weird kind of line splitting: If a line contains more than 75 characters, insert a "CR, LF, space" sequence. Thus the following line:
...
2
votes
1answer
205 views
How to join vCards lines
vCard uses a special way to split long lines: At 75 characters, insert a DOS newline and a space. Joining therefore means to replace all occurrences of the sequence "CR, LF, space" with an empty ...
2
votes
1answer
183 views
Replace “<?php print t('Blabla'); ?>” to be “Blabla”
Lets say in file.php, there is lots of php print text: <?php print t('Blabla'); ?>, <?php print t('Text Here'); ?>, etc.
What I need is to remove <?php print t(' and '); ?> of the ...
0
votes
1answer
119 views
How to replace text after the cursor location in VIM
Suppose I have one line:
Linux is not_ Linux
My cursor lies on the _ mark and I want to replace the second Linux to Unix,how can I do that in vim?
2
votes
2answers
519 views
regex replace text in xml file within node from the command line
I have an XML file and I would like to replace everything that is between the open and closing tag within multiple instances of the g:gtin node with nothing.
Is this possible from the command line, ...
3
votes
4answers
361 views
Replace whole line in a file from command-line
I have a text file which has some contents similar to this:
# General information about the project.
project = u'Py6S'
copyright = u'2012, Robin Wilson'
# The version info for the project you're ...
2
votes
1answer
855 views
Replace using VIM, reuse part of the search pattern
I am working with VIm and trying to set up a search and replace command to do some replacements where I can re-use the regular expression that is part of my search string.
A simple example would be a ...
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 ...
3
votes
2answers
850 views
use awk to replace parentheses?
How can I use awk to replace the parentheses in these 2 scenarios?
Change empty parens to the word "None"
192.168.0.24,Up,()
Remove parens to only host.domain.com is left
...
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 ...
2
votes
4answers
1k views
Using sed to convert newlines into spaces
Say I have a shell variable $string that holds some text with several newlines, e.g.:
string="this
is
a test"
I would like to convert this string into a new string new_string where all line breaks ...
7
votes
8answers
3k views
How can I “cat” a file and remove commented lines?
I'd like to know if there is a way that I could cat file like php.ini and remove all lines starting with ;
For example, if the file contained this:
; - Show all errors, except for notices
;
...
4
votes
2answers
663 views
Replacing identical NIC cards creates eth1 instead of using eth0 in Ubuntu
I changed out a NIC card that was the exact same make and model. The setup process for Ubuntu 11.04 was very seemless and easy so I figured it would be smart enough to setup up the replacement card. ...
2
votes
1answer
339 views
Replace complex string in several files
A hacker got into a web server and added this string (removed some characters for security purposes and added line breaks for readability) in all index.php files:
<?php
...
-2
votes
1answer
173 views
Linux “rpl” command doesn't replace text [closed]
I'm using rpl program in linux to replace date( with pdate( in some files.
But it says A Total of 0 matches replaced in 1 file searched.
while grep output for date( is:
...
7
votes
2answers
3k views
Replace string with contents of a file using sed
I have two different files:
File1
/home/user1/
/home/user2/bin
/home/user1/a/b/c
File2
<TEXT1>
<TEXT2>
I want to replace the <TEXT1> of File2 with the contents of File1 ...
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 ...
2
votes
3answers
273 views
Collapse repeating characters
Is there a more Bashist way than echo "$PWD//" | sed -e 's#//\+#/#g' to replace repeating slashes with a single one?
Thanks Steven D, now there's a fully working function to find the longest common ...