I have a csv whose tail is missing column data, e.g. the following:
Data1,Data2,User
abc,def,foo
hij,klm,foo
nop,qrs
tuv,wxy
In this case I want to add bar
to the end of the rows without foo
. That’s easily accomplished with sed '/foo/!s/$/,bar/'
. The issue is that this will add a ,bar
to the first line as well. I know that I can skip the first like with a 2,$
but when I do that it seems to not respect both “line number” and “negated search” instructions. Is there a way inside sed to incorporate both?
(To be clear I know I have other options. I can probably do multiple sed operations, or I can write a simple macro in vim and be done in a second as well. But in this case I want to see if it can be done entirely in a single sed.)