Re: remove newlines / perl /concise example

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



----- Original Message -----
| On Sat, Jan 01, 2011 at 03:42:46PM +0000, Dave Cross wrote:
| > Code like this is often simpler if you use the Unix filter model and
| > let the operating system take care of opening all the files.
| >
| >   #!/usr/bin/env perl
| >
| >   use strict;
| >   use warnings;
| >
| >   chomp(my @lines = <>);
| >
| >   print @lines;
| 
| That's one way of using up a lot of memory.
| 
| > If this is in a file called 'join', you can run it like this:
| >
| >  $ ./join < input.txt > output.txt
| 
| Use the tools you've already got as part of the OS install:
| /usr/bin/tr -d '\012' < input.txt > output.txt
| 
| --
| 
| rgds
| Stephen
| _______________________________________________
| CentOS mailing list
| CentOS@xxxxxxxxxx
| http://lists.centos.org/mailman/listinfo/centos

You could have used /usr/bin/tr -d "\n" < input.txt > output.txt .  It looks a bit cleaner and indicates that no special incantation or knowledge of the ASCII character set is required.

-- 
James A. Peltier
Research Computing Group
Simon Fraser University - Burnaby Campus
Phone   : 778-782-6573
Fax     : 778-782-3045
E-Mail  : jpeltier@xxxxxx
Website : http://www.sfu.ca/itservices
          http://blogs.sfu.ca/people/jpeltier


_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos


[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux