ChessUSA.com TalkChess.com
Hosted by Your Move Chess & Games
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

looking for a tool to conver line endings
Post new topic    TalkChess.com Forum Index -> Computer Chess Club: Programming and Technical Discussions Flat
View previous topic :: View next topic  
Author Message
Horacio Montenegro



Joined: 03 Sep 2008
Posts: 33

PostPost subject: Re: looking for a tool to conver line endings    Posted: Sun Mar 18, 2012 5:08 pm Reply to topic Reply with quote

I am not fluent on perl one-liners, but now I am jealous of the previous posts, so here is a (untested) script to convert to / from any OS specific format:

Code:
#!/usr/bin/perl
open (fh_in, "<", $ARGV[0]) or die "could not open file $!";
open (fh_out, ">", $ARGV[1]) or die "could not open file $!";

while (<fh_in>)
{
   $_ =~ s/\r//;
   $_ =~ s/\n//;
   $_ =~ s/\s+$//;
   if ( $ARGV[2] =~ m/mac/i ) { $_ = $_."\r"; }
   elsif ( $ARGV[2] =~ m/unix/i ) { $_ = $_."\n"; }
   elsif ( $ARGV[2] =~ m/windows/i ) { $_ = $_."\r\n"; }
   print fh_out;
}
close (fh_in);
close (fh_out);


just save this as whatever_you_like.pl, then make it executable:

Code:
 chmod +x whatever_you_like.pl


and call it as:
Code:
 ./whatever_you_like.pl input_file output_file SYSTEM


SYSTEM being any one choice of mac, unix or windows (case-insensitive). Again, untested, if does not work, just get back here and someone will point to any possible errors.

edit: this assumes you are developing on unix/mac, if not, you have to call the script as:
Code:
perl whatever_you_like.pl input_file output_file SYSTEM
Back to top
View user's profile Send private message
Display posts from previous:   
Subject Author Date/Time
looking for a tool to conver line endings Richard Vida Sun Mar 18, 2012 2:28 pm
      Re: looking for a tool to conver line endings Horacio Montenegro Sun Mar 18, 2012 2:44 pm
      Re: looking for a tool to conver line endings Ignacio Garcia Sun Mar 18, 2012 3:16 pm
      Re: looking for a tool to conver line endings Lucas Braesch Sun Mar 18, 2012 3:30 pm
      Re: looking for a tool to conver line endings Robert Hyatt Sun Mar 18, 2012 4:03 pm
            Re: looking for a tool to conver line endings Ignacio Garcia Sun Mar 18, 2012 5:42 pm
                  Re: looking for a tool to conver line endings Robert Hyatt Mon Mar 19, 2012 3:43 am
      Re: looking for a tool to conver line endings Horacio Montenegro Sun Mar 18, 2012 5:08 pm
      Re: looking for a tool to conver line endings Richard Vida Sun Mar 18, 2012 6:29 pm
            Re: looking for a tool to conver line endings Ignacio Garcia Sun Mar 18, 2012 7:07 pm
            Re: looking for a tool to conver line endings Sven Schüle Sun Mar 18, 2012 11:10 pm
                  Re: looking for a tool to conver line endings Ignacio Garcia Mon Mar 19, 2012 12:37 am
                        Re: looking for a tool to conver line endings Horacio Montenegro Mon Mar 19, 2012 3:45 am
                              Re: looking for a tool to conver line endings Sven Schüle Mon Mar 19, 2012 10:37 am
                        Re: looking for a tool to conver line endings Robert Hyatt Mon Mar 19, 2012 3:47 am
                        Re: looking for a tool to conver line endings Sven Schüle Mon Mar 19, 2012 10:58 am
                              Re: looking for a tool to conver line endings Ignacio Garcia Mon Mar 19, 2012 11:54 am
            Re: looking for a tool to conver line endings Lucas Braesch Thu Mar 22, 2012 12:58 pm
                  Re: looking for a tool to conver line endings Don Dailey Thu Mar 22, 2012 2:15 pm
                        Re: looking for a tool to conver line endings Gary Thu Mar 22, 2012 3:25 pm
                              Re: looking for a tool to conver line endings Don Dailey Thu Mar 22, 2012 4:22 pm
      Re: looking for a tool to conver line endings Don Dailey Mon Mar 19, 2012 1:52 pm
Post new topic    TalkChess.com Forum Index -> Computer Chess Club: Programming and Technical Discussions

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Powered by phpBB © 2001, 2005 phpBB Group
Enhanced with Moby Threads