What's the portable way to delete the first line1 from the pattern space ?
With gnu sed
I can do
s/[^\n]*\n//
but as far as I know this (using \n
in a bracket []
expression) is not portable.
Practical example: here, sed
prints the last section of the file including the delimiter via portable code. I'd like to remove the first line from the pattern space so as to exclude the delimiter and do that in a portable manner. With gnu sed
it's simple:
sed 'H;/===/h;$!d;//d;x;s/[^\n]*\n//' infile
1: Obviously this should be done without restarting the cycle of commands…
Best Answer
One way to portably do this sort of a thing is as follows: