Delete multiple lines w/ sed

Hi all,

I am trying to figure out the syntx to delete multiple lines w/ sed. I know the following syntax will delete lines 1 THROUGH 5 from filex:

sed 1,5d filex

But I wan to delete lines 1 AND 5 (keeping lines 2,3, and 4). Does anyone know how to do this in a single sed statement?

THANKS!!
-bookoo

If you are using sh/ksh/bash/zsh:

sed '1d
5d' filex

I.e., you need the line break.

The awk version is a bit more direct:

awk 'NR!=1 && NR!=5' filex

This takes advantage of the default awk action, which is to print the input line. This method simply accepts all lines except 1 and 5.

It can be generalized:

#!/bin/sh
while getopts s: arg; do
    case $arg in
    s)  skip="$OPTARG"
    esac
done
shift `expr $OPTIND - 1`
awk -v "sl=$skip" 'BEGIN {
        split(sl, a, ",")
        for (i in a) skip[a] = 1
    }
!skip[NR]' "$1"

Modern versions of sed support:
sed '1d;5d'

Even the very first version of sed will support:
sed -e 1d -e 5d