0

I need to remove a 3 character substring from a document, which could be located anywhere in the document, eg.

text
text
text
bla bla bla -ri bla bla bla
text
text
text

I would like to search for -ri and remove it to obtain

text
text
text
bla bla bla bla bla bla
text
text
text

If this were a fixed line and character number I'm pretty sure I could excise it with sed or cut, but I am not sure how to do it if the line and character position are variable. Is this possible?

2 Answers 2

4

You don't need to know the line number, you can have sed unconditionally (try to) modify each and every line:

$ sed -e 's/-ri //' < input > output

It gets more awkward if you have matches on multiple lines, and want to handle only some of them.

2

sed can be used for tasks like this:

sed 's/-ri //g' path/to/file

will find every occurance of -ri and replace it with nothing using the s substitute operate in sed

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.