Linked Questions
10 questions linked to/from Replace string with contents of a file using sed
4
votes
1
answer
3k
views
How to insert file content after a certain string in a file? [duplicate]
we have for example this file
cat exam.txt
I am expert linux man
what we can do for out country
I love redhat machine
"propertie"
centos less then redhat
fedore what
my name is moon yea
we want to ...
9
votes
3
answers
10k
views
Insert text from file inline after matching pattern in another file
I'm trying to take the contents of a file and insert it after a matching pattern in another file using sed. My question is very similar to this question, but I wish to insert the contents of a file ...
11
votes
4
answers
15k
views
sed load substitute from file [duplicate]
I'm attempting to replace a pattern in a file with the complete contents of another file using sed.
Currently I am using:
sed "s/PATTERN/`cat replacement.txt`/g" "openfile.txt" > "output.txt"
...
12
votes
3
answers
4k
views
How to replace text between two markers in a file with a section of text from another file?
Say I had a block of text in the ~/.bashrc:
#~/.bashrc
# ...some commands...
# aliases
alias suicide='sudo rm -rf /'
# end aliases
# other commands
I wish to replace that block of text with some ...
2
votes
3
answers
10k
views
"bad flag in substitute command: '{" while replacing a string with sed from one file to another file
I am trying to replace strings found in File1 with strings in File2
File1
<IMG SRC="/Repository/GetImage.dll?baseHref=Orange/2011/03/27&EntityID=Ad12911&imgExtension=" />
<...
4
votes
3
answers
2k
views
Find and replace with contents of a file
I have a file that begins with a few "include" statements, like this:
include foo.xyz
include bar.xyz
do c
do d
Suppose the file foo.xyz contains do a and the file bar.xyz contains do b. How can I ...
3
votes
2
answers
1k
views
How to read needle part of the sed command from a file?
I want to replace a long part of a file with something else preferably by sed but want to read that long part from a file. I already found this:
sed -e '/<TEXT1>/{r File1' -e 'd}' File2
from ...
2
votes
1
answer
3k
views
Replace one block of text with another block of text when replacement text is in a file
I have two files. The fist file is an existing C/C++ source file (*.cpp). The second is a text file (*.txt) and contains one function. The function is in both files, and it needs to be copied from the ...
1
vote
3
answers
147
views
sed to replace in a file, with both old and new strings in files
I want to automatically comment out a code block in PHP file, as below:
The original block:
// Enable all errors
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
...
0
votes
2
answers
141
views
Run program only on matching lines
Let's say I have a program blackbox, and a file with the following contents:
in this file
this line contains =TAG=
so does =TAG= this one
as =TAG= does this other line
this line does ...