1

Currently I have this sed:

sed -i '/[^}.to]\.to[[:space:]]/ s/\(\S\)/expect(\1/' ../_spec_seded/"$file"

which adds "expect(" at the start of lines that have ".to" (but not "{.to")

How can I make this so that it matches lines with both ".to" and also ".to_not"?

I tried

sed -i '/[^}.to]\.to([[:space:]]|_not)/ s/\(\S\)/expect(\1/' my_file

basically changing [[:space:]] to ([[:space:]]|_not) to try and match .to OR .to_not but this messed it up for both, not adding the expect at the start.

5
  • Can you include some sample data?
    – slm
    Nov 10, 2013 at 1:51
  • w/o seeing the data, seems like you could do a .to|.to_not.
    – slm
    Nov 10, 2013 at 1:53
  • will try but bit hard as this is in the middle of other sed operations. I did update the Q a little (removed 'start' of line for the .to). Nov 10, 2013 at 1:56
  • I can't see what you're actually trying to do. What's with the [[:space:]]?
    – slm
    Nov 10, 2013 at 1:59
  • Is that } flipped in pattern vs. but not "{.to"?
    – Runium
    Nov 10, 2013 at 2:20

1 Answer 1

1

Does this do what you want?

sed '/{\.to/b;/\.to\(_not\|\)\s/s/^\s*/\0expect(/' file

alt:

sed '/{\.to/b;/\.to\(_not\|\)[[:space:]]/s/^[[:space:]]*/\0expect(/' file

Sample:

$ diff -ytW 48 infile <(./sed_script)
.to do                 |  expect(.to do
  .to SPACE and        |    expect(.to SPACE and
        .to TAB        |          expect(.to TAB
some s                    some s
day x                     day x
.to r                  |  expect(.to r
.tofry                    .tofry
not t                     not t
.to     tab            |  expect(.to      tab
{.to not me               {.to not me
{.to nor me               {.to nor me
when e                    when e
        {.to Nope                 {.to Nope
.to_not BUT yes!       |  expect(.to_not BUT yes
  {.to Oh nono              {.to Oh nono
.to_notX                  .to_notX
.do s                     .do s
{.to not do me            {.to not do me
so d                      so d

|--- Original file ----|--- modified file ----|

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .