For e.g. I want to delete the second and the fourth word of each line
Before sample.txt:
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nulla elit dui, fermentum sed quam sed, semper auctor elit.
After sample.txt:
Lorem dolor amet, consectetur adipiscing elit.
Nulla dui, sed quam sed, semper auctor elit.
You can do this with "cut"
The
-d
sets the delimiter to space and the-f
chooses fields 1, 3 and 5+.Something like:
should work, if you must use sed. This script does not work if you have fewer than 4 words in the line.