rouben@math16.math.umbc.edu (Rouben Rostamian) (05/30/91)
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? |... |[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' '<some char.>' as a work around).] To concatenate lines ending in a ':' to the following line using sed, do: sed '/:$/{N; s/\n//; }' <infile >outfile -- Rouben Rostamian Telephone: (301) 455-2458 Department of Mathematics and Statistics e-mail: University of Maryland Baltimore County bitnet: rostamian@umbc.bitnet Baltimore, MD 21228, U.S.A. internet: rouben@math9.math.umbc.edu
subbarao@phoenix.Princeton.EDU (Kartik Subbarao) (05/30/91)
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. " > ugh, sed.. >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' '<some char.>' as a work around).] I can do this without thinking in perl :-) : perl -ne 'chop if (/:$/); print;' sed....umm, I tried a bunch of line-noise-like looking things, none of which worked. For some reason I couldn't get everything except the terminating newline in a pattern. Oh well, I'm sure tons of other people know how :-) -Kartik sed -nm -- internet% whoami subbarao@phoenix.Princeton.EDU -| Internet kartik@silvertone.Princeton.EDU (NeXT mail) SUBBARAO@PUCC.BITNET - Bitnet
rbr@bonnie.ATT.COM (228-4197,ATTT) (05/31/91)
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' '<some char.>' 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
krk@cs.purdue.EDU (Kevin Kuehl) (06/01/91)
In article <1991May31.163100.20328@cbnewsl.att.com> rbr@bonnie.ATT.COM (228-4197,ATTT) writes:
Why not use "ed(1)" as:
....
If you want to double space, use sed or awk. Both of these will do
the trick:
$ sed G < input > output
$ awk '{ print $0 "\n" }'
--
Kevin Kuehl
krk@cs.purdue.edu