Reputation: 13
So I have a bunch of files that I want to edit at once using sed
but the problem is that I need to edit a line and change the text to a file name stored in variable filename. Every time I tried, it changes the text to the literal "filename" and I don't know how to fix it.
The command I've used is:
sed -i 's/$x/'$filename'/g' *.html
Upvotes: 1
Views: 724
Reputation: 58430
This might work for you (GNU parallel and sed):
parallel --header : sed -i 's#{x}#{filename}#' {file} ::: file *.html ::: x pattern ::: filename name
Upvotes: 1
Reputation: 12090
From your description and the command used I assume that you try to replace a variable text stored in
X="text2replace"
with a filename stored in
FILENAME="filename"
According this, a command like
sed -i "s/${X}/${FILENAME}/g" *.html
should do the job. It will replace all occurrences of text2replace
in all HTML files found with the string filename
.
You may have also a look into
Upvotes: 2