It's not straightforward, but it can be done.
Archive of posts filed under the faq category.
The mythical “idempotent” file editing
Stop asking for that.
“Range of fields” in awk
This is asked very often, and the solution isn't always obvious (if at all).
Pulling out strings
Some ways to "pull out" strings from files
Replace every Nth occurrence
Problem statement: replace every Nth occurrence of a pattern. For bonus points, provide context to the match. For this article, we're going to use this example (mostly nonsensical, but that illustrates the concept): 1foo1 bar foo 2foo3 abc def foo foo foo 1foo4 foo foo 3foo9 4foo7 zzz 7foo7 3foo3 And we want, among all […]