How to replace some specific words from file?

I have the file like this.

cat 123.txt
<p> <table border='1' width='90%' align='center' summary='Script output'> <tr><td>text </td> </tr> </table> </p>

I want to replace some tags and want the output like below. I tried with awk & sed commands. But no luck. Could someone help me on this?

cat 123.txt
<tr><td>text </td> </tr>

To find out what was wrong with your sed - and awk -commands it would greatly help to post them. As a matter of fact my crystal ball is in repair right now, so you will have to post your code.

bakunin

replace = remove? And, by what criteria?

based on your given input and output.

bash-4.1$ grep -o "<tr.*/tr>" a.txt
<tr><td>text </td> </tr>

bash-4.1$ sed "s#.*<tr#<tr#;s#/tr>.*#/tr>#" a.txt
<tr><td>text </td> </tr>

From what you have told us, this will achieve your output, but I would bet my house it isn't what you really want:-

echo "<tr><td>text </td> </tr>" > 123.txt

You need to tell us how/why a transformation is performed and what attempts your have made so far so we can try to understand your needs properly. Output/errors are very useful in diagnosing where it's not doing quite what you want, but you would need to show some meaningful input & desired output before we can be sure we are going in the right direction.

Robin

1 Like