#!/usr/bin/sed -f # usage: fbasename file # or # usage: find path -print | fbasename # # # this is a basename, but read filenames from stdin, each line # contains the path and a possible suffix # # this will produce one output line per input line, with # the filename component of path, with the (possible) suffix # removed s/^[ ]*// s/[ ]*$// t c : c s/[ ][ ]*/\ / t a s/\/*$// s/.*\/// b : a h s/.*\n// x s/\n.*// s/\/*$// s/.*\/// t b : b G s/^\(.*\)\(.*\)\n\2$/\1/ t P d ### colorized by sedsed, a sed script debugger/indenter/tokenizer/HTMLizer ### original script: http://pcsiwa.rett.polimi.it/~paolob/seders/scripts/fbasename.sed