I have a script for the R statistical package that I’m trying to modify using SED. Right now, it looks like this:
foo = [something unimportant]
summary(foo)
I’d like it to look like:
foo=[something unimportant]
print('foo')
summary(foo)
I’ve tried:
sed 's/summary\((.+)\)/print\(\'\1\'\)\nsummary\(\1\)/' <infile.txt >outfile.txt
but that seems to not work. I have the feeling my regex-fu is lacking. Any suggestions?
I think you’re looking for
sed "s/summary(\(.*\))/print('\1')\n\0/" .... Sed uses posix regex, where ( and ) aren’t special characters. Instead, groups are delimited by\(and\).Input:
Output: