I am running the following sed command. I want to extract every 4th line starting at the second line:
input:
$ sed -n '2~4p' filename
output:
sed: 1: "2~4p": invalid command code ~
Does anyone know why this is occurring? I am using mac OSX 10.8.
I know the following awk command command will do: $ awk "NR%4==2 {print}"
I'm curious why tilde is invalid for this sed command.
I guess you're in Mac OS X. It has the BSD implementation of sed
and if you search for ~
in the man
page you'll find nothing, because it's not there.
You can install the GNU implementation, for example with MacPorts:
sudo port install gsed
or Brew:
brew install gnu-sed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With