Need sed to do something which sounds simple

Manish Jain invalid.pointer at gmail.com
Thu May 28 12:48:46 UTC 2009


Hi,

I need sed to do something which sounds simple, but I can't figure out 
the right command. All I need to do is insert a blank after a '}' at the 
end of a line if the next line begins immediately afterwards (i.e. with 
no blank line between).

//abc.cpp :
int myclass::fx(int * arg)
{
	if(! (isValid()))
	{
		return -1;
	}
	return ptr->fx(arg);
}

//what-i-want.cpp :
int myclass::fx(int * arg)
{
	if(! (isValid()))
	{
		return -1;
	}
	
	return ptr->fx(arg);
}

The commands I have tried are :

i)
sed -e 's/\(}$\)\n\(^[[:space:]]*[[:alpha:]]\+\)/\1\n\n\2/' \
<abc.cpp  >what-i-want.cpp

ii)
sed -e 's/\(}$\)\(^[[:space:]]*[[:alpha:]]\+\)/\1\n\2/' \
<abc.cpp  >what-i-want.cpp

but obviously neither works, which is why posting this message.

Can anybody please tell me what the correct command would be like ?


Thank you &
-- 
Regards
Manish Jain
invalid.pointer at gmail.com
+91-96500-10329

Laast year I kudn't spell Software Engineer. Now I are won.


More information about the freebsd-questions mailing list