Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: sed/vi how to concatenate all non-empty lines?



At Wed, 25 Jul 2001 03:39:18 +0000,
Jean-Christian Imbeault wrote:

> So how to I get sed or vi to concatenate all lines within a paragraph into 
> one linebut keep the empty lines between paragraphes? (i.e. concatenate all 
> consecutive non-empty lines together)?

$ cat -s input.txt | sed join.sed

join.sed is: BEGIN--cut here--cut here
#n

/^ *$/!{
	H
}
/^ *$/{
	x
	s/\n/ /g
	s/^ //
	p
}
${
	x
	s/\n/ /g
	s/^ //
	p
}
END--cut here--cut here

Don't forget '#n', or use 'sed -n' instead.

-- 
OZAWA -Crouton- Sakuro
E-Mail: mailto:crouton@example.com
   Web: http://www.weatherlight.org/~crouton/
   PGP: C98F 74E0 AEEB 4578 1DFC  F650 3BE0 9627 11FC C9F5
VERBA VOLANT, SCRIPTA MANENT


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links