#everything but the last x lines: x=10;seq -s $'\n' 1 30 | sed -n ':s;1,'$((x-1))'{N;bs};{N;P;D}' #everything but the first y lines and the last x lines: y=5;x=10;seq -s $'\n' 1 30 | sed -n '1,'$y'd;:s;1,'$((y+x-1))'{N;bs};{N;P;D}' #stop at the 6th line matching foo: sed '/foo/{H;x;s/\(\n.*\)\{6\}//;tq;x;b;:q;q}' #join the lines of paragraph separated by a blank line: sed ':s;{N;s/\n\(.\{1,\}\)/ \1/;ts;s/\n//}' # grep -o '"[^"]"' sed -n $'s/[^"]*"\\([^"]*\\)"/\\1\\\n/;te;D;:e;P;D' sed $'s/[^"]*"\\([^"]*\\)"/\\1\\\n/;te\nD;:e\nP;D' #change the newline into ', ' sed '1!s/^/ /' | paste -s -d ',' sed ':s;$!{N;s/\n/, /;bs}' #print then n th block delimited by ## sed -n '/##/{x;s/a\{'$n'4\}/&/;tb;s/^/a/;x;b;:b;x;:a;p;n;/##/!ba;p;q} tree(1): find ./ -type d -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g #remove all occurence of foo...the unreadable one: echo "foo bar foo" | sed ':;;\;foo;s;;;;t;' #tac sed 'x;1!H;$!d;g' file (oneliners version: sed '1!G;h;$!d')