Replace a line of a file with a blank line in shell script?
<p>I have a text file called catalog where each line has a name, a surname, a city and a phone number like this:</p>

<pre><code>John McJohn Detroit 0301234568
Donald Duck Lake_City 1234567890
Deez Nutz Oxford 2305985531
</code></pre>

<p>and I want to write a script that will take a keyword as a parameter and will replace its line with the keyword with a blank line.</p>

<p>here's where i got so far:</p>

<pre><code>t1=$(grep $2 catalog)      #$2 is the keyword
echo the lines with that keyword are:
echo $t1

t2=$(echo)                       #a blank line

t3=$(tr '$t1' '$t2' &lt; catalog)  #replacing each line with the keyword with a space

echo The lines have been deleted  #not really, they have been replaced with a space

cat catalog
</code></pre>

<p>This doesn't change the file at all.</p>

<p>I've tried numerous expressions of sed, without any luck (I run the scripts on an old xubuntu version, so I don't know if the sed is supposed to work on this).</p>

<p>I've tried to replace the "t2=$(echo)" thing with '\n' but if fails miserably.</p>

<p>How can this be made?
Is replacing each line with a pattern to a blank line possible at all?</p>

<p>(possible and "works-fine" answer:</p>

<pre><code>t1=$(grep $2 catalog)     
echo the lines with that keyword are:
echo $t1
sed "./*$t1.*/s///" catalog
sed "./*$t1.*/s///" catalog &gt; catalogtemp
mv catalogtemp catalog
</code></pre>

<p>)</p>