I have a sed script that has:sed -i '/ *it.*do/! {          /\.should/ {            s/\.should/)\.to/            s/\(\S\)/expect(\1/             # ...othersThe last s adds expect( to the start of the line.  I don't understand how it works.It works though for:Original:  it uses the given count if set do    call('5').should == 5  end  it uses the processor count from Parallel do    call(nil).should == 20  endAfter:  it uses the given count if set do    expect(call('5')).to eq 5  end  it uses the processor count from Parallel do    expect(call(nil)).to eq 20  endBut it doesn't add the expect( for:Original:  it does not wait if not run in parallel do    ParallelTests.should_not_receive(:sleep)    ParallelTests.wait_for_other_processes_to_finish  end  it stops if only itself is running do    ENV[TEST_ENV_NUMBER] = 2    ParallelTests.should_not_receive(:sleep)    with_running_processes(1) do        ParallelTests.wait_for_other_processes_to_finish      end  endAfter - no expect(...  it does not wait if not run in parallel do    ParallelTests).to_not receive(:sleep)    ParallelTests.wait_for_other_processes_to_finish  end  it stops if only itself is running do    ENV[TEST_ENV_NUMBER] = 2    ParallelTests).to_not receive(:sleep)    with_running_processes(1) do        ParallelTests.wait_for_other_processes_to_finish      end  endHowever it DOES work for:After:  it should be true when there is a Gemfile do    use_temporary_directory_for do      FileUtils.touch(Gemfile)      expect(ParallelTests.send(:bundler_enabled?)).to eq true    end  end
How can sed add text after existing indent?
sed
It is just a character class, since you do not have the -r flag set the \( and \) makes a group for latter reference, and \S is just the complementary group for \s, since \s is the group that matches any white-space \S is the group that matches anything but white-space.This means that the regex s/\(\S\)/expect(\1/ adds expect( on front of the first non white-space:# echo ' ' | sed s/\(\S\)/expect(\1/# echo '   a' | sed s/\(\S\)/expect(\1/   expect(aSo, I guess that I'm trying to say that your script does change the line:ParallelTests.should_not_receive(:sleep)It must change it:# echo ParallelTests.should_not_receive(:sleep) | sed '/ *it.*do/! {    /\.should/ {        s/\.should/)\.to/        s/\(\S\)/expect(\1/     }}'expect(ParallelTests).to_not_receive(:sleep)