I know I can match periods with \. but through trial and error I can still not seem to have my pattern ignore the period character.

I have tried variations such as:

\[^.] \[^.]+

I want to have code such as

foo("some text").arg("more text");

be untouched while code such as

foo("some text");

match a pattern and be replaced with something else

Also, I Have run into another issue

A case such as:

tr("I am some text") .arg(i do stuff) .arg(I also do stuff) where it needs to be handled from 2 up to n lines of this.

I want this sort of text to be left alone because as of now, the tr would be deleted and would cause a syntax error.

  • 1
    What do you mean by "ignore" ? Updating the question and providing some examples of what you want to match why why you want to "ignore" the period character might help. – Stephen Harris Aug 30 '16 at 18:47

To be a "non-period" then the sequence [^.] is what you want. In your examples you have a \ in front of the [, which is wrong.

So, for example:

foo("some text").arg("more text");
foo("some text");

% sed 's/foo("some text")[^.]/replaced text/' tstfile
foo("some text").arg("more text");
replaced text

Note that this also replaced the character following the foo(..). If you want to keep that then we can remember it:

% sed 's/foo("some text")\([^.]\)/replaced text\1/' tstfile
foo("some text").arg("more text");
replaced text;
  • so for a code sed -i '/\btr(/{ :a; s/\btr(\([^)]*\))[^.]/\1/I; t; N; ba}' $file how would I keep that non-period character after the text inside the parentheses (\1) – Klamz Aug 30 '16 at 19:09
  • I'd try replacing [^.] with \([^.]\) and then have \1\2 as your replacement – Stephen Harris Aug 30 '16 at 19:11
  • okay, I was trying that without the two slashes with \1\2 and that just doesn't make sense. Thanks for opening my eyes – Klamz Aug 30 '16 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.