I saw so much questions about the sed
command but none match my dude.
I want to substitute the entire line which contains a pattern.
I think the sed
command is the best option. I started with this sed
command but doesn't work
sed -i 's/pattern/Substitution/' myfile.txt
After that i'm testing with this other command but only substitute the pattern, not the entire line.
echo "hello y luego bye" | sed "s|hello|adeu|g"
You need to match the whole line containing that pattern and then replace. Use it like this:
I also added
\b
for word boundaries so that you only matchpattern
but avoid matchingpatterns
.Explanation:
^.*\bpattern\b.*$
us used to make sure whole line is matched containing pattern.^
is line start and$
is line end..*
matches 0 or more length text. So^.*
matches all the text beforepattern
and.*$
matches all the text afterpattern
.Using awk you can do: