Reputation: 148
Hi, I have an issue replacing a specific line (with an empty line) in several files using sed. I guess cause the string I want to replace contains the character '>' or '<'because if I remove it, it works fine. I want to replace the string with an empty line
This is what I wrote (it doesn't work):
sed -i 's/<field outputName="location">//g'
Thanks to everyone that suggest a solution.
Upvotes: 1
Views: 48
Reputation: 627537
You can use
sed -i '/<field outputName="location".*>/s/.*//' file
Here,
/<field outputName="location".*>/
- finds lines that contain <field outputName="location"
, then any text and then a >
chars/.*//
- replaces the whole line found with an empty string.See an online demo:
#!/bin/bash
s='Text start
... <field outputName="location"> ...
End of text.'
sed '/<field outputName="location".*>/s/.*//' <<< "$s"
Output:
Text start
End of text.
Upvotes: 1