From af137@torfree.net Sat Oct 19 16:48:10 1996 Newsgroups: comp.editors Path: fu-berlin.de!news.mathworks.com!news-peer.gsl.net!news.gsl.net!ix.netcom.com!tor-nn1.netcom.ca!torfree!af137 From: af137@torfree.net (Al Aab) Subject: . SED squeeze empty lines,extract titles, etc Message-ID: Organization: Toronto Free-Net X-Newsreader: TIN [version 1.2 PL2] Date: Sat, 19 Oct 1996 06:12:51 GMT Lines: 47 1- as an excercise for sed gurus : extract last line of every paragraph. 2- squeeze empty lines: a- he solaris man page shows a looong script. b- oreilly's sed and awk has a shorter script. c- reminiscent of APL 1liners, here is the shortest sed script i've seen ( due - i guess - to the famous unix wizard : brian hiles whose work should be added to unix or unix faq. ) : sed "/./,/^ *$/!d" datafile 3- to extract the first line of every paragraph : # extract the title lines form a data file ## a title line is any line preceded by 1 or more empty lines wrong script : sed "1{/./!d;};/^ *$/,/./{/./!d;}" d correct script : sed -n "1{/./p;};/^ *$/,/./{/./p;}" d -------------------------- sample data file -------------------------------- title 1 (the first line in the data file may or may not be empty) ssssss tttttttt title 2 uuuu title 3 vvvv www title 4 xx yyy title 5 (last line may or may not be empty.) ---- end of data file (notice the last line has will be considered a title) -- -- =-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- al aab, seders moderator sed u soon it is not zat we do not see the s o l u t i o n -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+