It is currently Tue, 07 Dec 2021 02:41:25 GMT



 
Author Message
 quick question
How can I get rid of the ^M's in my text files when I open a file
created in unix on a windows machine?

Is there a quick perl-script I could use?

TIA
-David



 Wed, 18 Jun 1902 08:00:00 GMT   
 quick question
In article <38C616DB.7866D...@che.utexas.edu>,
  David Punsalan <punsa...@che.utexas.edu> wrote:

This is a pain in the famous behind. I don't know if using Perl to
remove ^M's is the best answer since other solutions already exists.

Usually I just do "<Esc> % <Ctrl>-q <Ctrl>-m <Ret> <Ret> !" in Emacs,
but if you really want a Perl script...

perl -e 'while (<>) { chomp; print "$_\n" }' <infile >outfile

(reading from STDIN, writing to STDOUT, **untested** (I don't have a
Windows text file here at the moment, and I'm proud of it))

/A

--
+---------------------+
| Andreas K?h?ri
| Uppsala University
| Sweden

Sent via Deja.com http://www.deja.com/
Before you buy.



 Wed, 18 Jun 1902 08:00:00 GMT   
 quick question

  AK> This is a pain in the famous behind. I don't know if using Perl to
  AK> remove ^M's is the best answer since other solutions already exists.

not many do it in less code.

        perl -pi -e 'tr/\cM//d' file

  AK> perl -e 'while (<>) { chomp; print "$_\n" }' <infile >outfile

  AK> (reading from STDIN, writing to STDOUT, **untested** (I don't have a
  AK> Windows text file here at the moment, and I'm proud of it))

and it is broken. if run on unix, $/ will be \n and the \r will not be
chomped. in fact what you wrote is a version of cp and nothing else.

the previous post showed a correct solution.

uri

--
Uri Guttman  ---------  u...@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com



 Wed, 18 Jun 1902 08:00:00 GMT   
 quick question
In article <x71z5l7v1o....@home.sysarch.com>,
  Uri Guttman <u...@sysarch.com> wrote:
[cut]

You're right, and I'm not going to defend myself.

/A

--
+---------------------+
| Andreas K?h?ri
| Uppsala University
| Sweden

Sent via Deja.com http://www.deja.com/
Before you buy.



 Wed, 18 Jun 1902 08:00:00 GMT   
 quick question
Far too complicated - the one liner is...

cat dosfile | tr -d '\r' > unix_file

Regards

Phil Q

--

Phil Quiney                             CSIP Demonstrator
pqui...@nortelnetworks.com              Nortel Networks,
Telephone: +44 (1279) 402363            London Rd, Harlow,
Fax:       +44 (1279) 402885            Essex CM17 9NA,
                                        United Kingdom.

"This message may contain information proprietary to Northern
Telecom so any unauthorised disclosure, copying or distribution
of its contents is strictly prohibited."



 Wed, 18 Jun 1902 08:00:00 GMT   
 quick question

  >> perl -e 'while (<>) { chomp; print "$_\n" }' <infile >outfile
  >>
  QP[> Far too complicated - the one liner is...

it was useless to boot.

  QP[> cat dosfile | tr -d '\r' > unix_file

and you get the useless use of cat award for the day.

tr -d '\r' < dosfile > unix_file

or on solaris:

dos2unix -ascii dosfile unixfile

and i posted a perl version as well.

uri

--
Uri Guttman  ---------  u...@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com



 Wed, 18 Jun 1902 08:00:00 GMT   
 quick question
Try:

sed 's/\^M//g' oldfile > newfile

Tracy



 Wed, 18 Jun 1902 08:00:00 GMT   
 quick question

dos2unix is around on plenty of Linux systems as well (given that this
is crossposted to cols, and now followups set). It's in the sysutils
package in Debian, I don't know about Red Hat et al.

--
Colin Watson                                           [cj...@cam.ac.uk]
"F(x) = d(y)/d(x)"  "This isn't the equation we're looking
 for.  Move along." - kei...@polarnet.ca, rec.arts.sf.written



 Wed, 18 Jun 1902 08:00:00 GMT   
 quick question

 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

   Errr, how come nobody has asked about the "backwardness"
   of the above description?

   I thought ^Ms (Carriage Returns) showed up when opening
   a file created in windows on a Unix machine.

   Use ASCII (text) mode when FTPing files between dissimilar systems.
   It will adjust the line endings for you.

--
    Tad McClellan                          SGML Consulting
    ta...@metronet.com                     Perl programming
    Fort Worth, Texas



 Wed, 18 Jun 1902 08:00:00 GMT   
 quick question

news:38C616DB.7866D8C5@che.utexas.edu...

Even easier if you FTP the script in ASCII mode.



 Wed, 18 Jun 1902 08:00:00 GMT   
 quick question

Right idea, hopelessly verbose; try

  tr -d '\r' < dos_file > unix_file

and save two keystrokes and a cat.



 Wed, 18 Jun 1902 08:00:00 GMT   
 
   [ 11 post ] 

Similar Threads

1. I have a Quick Question, need quick answer.

2. Quick question regarding Solaris 9

3. steps for changing modules.conf .. quick question

4. Quick question regarding 'includes'

5. quick question about compatibility of desktop environments

6. Quick Question

7. Quick Question

8. Quick Question

9. Quick Question...

10. easy quick question...


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software