With my shell script, when I run ./Test1 hello result.
It is supposed to take hello as standard input and result as standard output. The shell should remove any whitespace before <td>, </td>, and abc
So, I write the script this way
tr -d [:blank:] < $1
grep -r "<td>" $1 | sed -r 's/<td>//g' > $2
sed -r 's/<\/td>//g' $2
sed -r 's/abc//g' $2
However, when I run this command, the content of result file is exactly the same as the content of hello file (the only difference is the whitespace is removed)
The file hello content:
<td>hello</td>
<td>hello</td>
<td>hello</td>
<td>abc</td>
<td>abc</td>
How do I get sed to apply the change to the target file?
If you want to store the changes from
sedback to the file use the-ioption:Edit: The regexp is clearer if we use a different separator with
sedand use the extended regexp option-r:The
?make the previous character optional so the/doesn’t have to be present making the regexp match<td>and</td>in one.