echo -e "a\nb\nc\nd\ne\nf\ng\nh" | sed '3,5a test'
This will match lines 3, 4 and 5.
But I am trying to match only lines 3 and 5 (not 4). And append 'test' after them.
If the operation is more complex than in this case then you can use a structure like this:
I.e. you put all commands you need between
And you add all your patterns (line numbers or whatever) after
What happens is this:
I try to tidy this up:
In a single line would be like:
Portably, you need to write it:
As @HaukeLaging aleady said, this command does what you want:
Now, this can become rather cumbersome to type if you want to match, e.g., 20 lines.
In these cases, assuming your shell supports brace expansion, you can use this command instead:
(Note that the braces and the comma must remain unquoted.)
As a result, the shell will pass the arguments to