Deleting newlines
Larry Wall
lwall at jpl-devvax.JPL.NASA.GOV
Fri Jan 5 13:33:47 AEST 1990
In article <990 at manta.NOSC.MIL> barajas at manta.NOSC.MIL (Albert A. Barajas) writes:
: Is there a quick and dirty way to delete newlines
: from an ascii text file?
Lotsa ways.
time awk '{printf "%s", $0}' < /etc/termcap > /dev/null
2.3u 0.0s 0:02 85% 55+102k 22+1io 4pf+0w
time awk 'BEGIN{ORS=""}{print}' < /etc/termcap > /dev/null
1.8u 0.0s 0:02 80% 49+100k 22+1io 4pf+0w
time tr -d '\012' < /etc/termcap > /dev/null
1.2u 0.0s 0:01 71% 8+41k 22+0io 3pf+0w
time perl -pe 'chop;' < /etc/termcap > /dev/null
1.0u 0.1s 0:01 65% 169+146k 22+5io 5pf+0w
It looks like perl is the quickest. Some would argue it's also the
dirtiest... :-)
I do not believe it is possible with sed except for very short files or
by using multiple passes. Even then I doubt you could get rid of the
final newline. Similar problems with ed.
The combination of sed and m4 has possibilities if you know what you're
translating won't interfere with m4.
If all your records are the same size, or you don't mind trailing blanks,
it can also be done with dd.
And you can always write a little echo loop in your shell.
There's probably a way to do it with adb, but I don't want to think about it.
There's also this quaint language called 'C'...
That's all I can think of, offhand, (other than rm, which deletes more than
just newlines).
Larry Wall
lwall at jpl-devvax.jpl.nasa.gov
More information about the Comp.unix.questions
mailing list