Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!zaphod.mps.ohio-state.edu!mips!pacbell.com!att!att!cbnewsl!bonnie!rbr From: rbr@bonnie.ATT.COM (228-4197,ATTT) Newsgroups: comp.unix.shell Subject: Re: sed to remove newlines? Keywords: sed Message-ID: <1991May31.163100.20328@cbnewsl.att.com> Date: 31 May 91 16:31:00 GMT References: <6356@iron6.UUCP> Sender: news@cbnewsl.att.com (NetNews Administrator) Reply-To: rbr@bonnie.ATT.COM (Bob Rager) Distribution: comp.unix.shell Organization: AT&T Bell Laboratories Lines: 34 In article <6356@iron6.UUCP> yeates@motcid.UUCP (Tony J Yeates) writes: >Is it possible to remove newlines (i.e. \n) from a file using sed? If >so how? We have tried various things without success: > >escaping \n -> \\n >double escaping \n -> \\\n >using \012 > >but with no success. Our man page incs. the following:- > >"\n Matches a NEWLINE embedded in the pattern space. " > >If this can only be used for pattern matching but not exchange, it would seem >to offer nothing over the use of $. > >[Our current requirement is to concatenate any lines ending with a ':' to the >next line in a file. Although I can think of numerous other uses ( we >usually end up using tr '\012' '' as a work around).] On input "sed(1)" converts the lint to a string. Therefore, the edit functions never see the "\n" newline character. I think you may have the wrong focus to solve the problem, think joining selected lines, not eliminating newlines. Why not use "ed(1)" as: cp $1 $2 ed - $2 \\E-O-C g/:$/j w q E-O-C Bob Rager