The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
removing pattern which is spread in multiple lines sabyasm Shell Programming and Scripting 2 05-13-2008 02:19 AM
Removing certain text from multiple filenames Djaunl UNIX for Dummies Questions & Answers 6 01-15-2008 02:52 PM
removing old files except configuration files and folders jamcalicut Shell Programming and Scripting 1 11-09-2007 01:34 PM
Please Help. Need Help searching for multiple stings in a file and removing them. mjs3221 UNIX for Advanced & Expert Users 2 08-19-2006 03:28 AM
Removing user from multiple groups via command line jquizon62 SUN Solaris 1 10-28-2004 09:56 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-15-2007
Registered User
 

Join Date: Sep 2007
Location: EX-PAT in Taipei, Taiwan
Posts: 105
Removing M^ from multiple files

to do this i usually type dos2unix <file> -o <file>
and this will remove the M^ from the end of each file. well i have over 100 files that someone copied that i need. how do i remove the M^. i saw a perl script but i am not familiar with .pl at all really
Reply With Quote
Forum Sponsor
  #2  
Old 11-15-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Perl not needed.

Try it in a test area first.....

Code:
#!/bin/sh

find directory -type f | while read N
do
          if dos2unix "$N" -o "$N".tmp
          then
                 mv "$N".tmp "$N"
          fi
done
Reply With Quote
  #3  
Old 11-15-2007
Registered User
 

Join Date: Sep 2007
Location: EX-PAT in Taipei, Taiwan
Posts: 105
sorry i just reread my post. i meant within the file there is the ^M not on the extensions.
Reply With Quote
  #4  
Old 11-15-2007
Registered User
 

Join Date: Sep 2007
Location: EX-PAT in Taipei, Taiwan
Posts: 105
sorry but it cannot find when i run the command

find: cannot open directory: No such file or directory
Reply With Quote
  #5  
Old 11-15-2007
Registered User
 

Join Date: Sep 2007
Location: EX-PAT in Taipei, Taiwan
Posts: 105
for f
do
mv $f ${f}~ && tr -d '\015\032' <${f}~ >$f
rm ${f}~
done

<script> <file>

this worked for me
thanks
Reply With Quote
  #6  
Old 11-15-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by deaconf19 View Post
sorry but it cannot find when i run the command

find: cannot open directory: No such file or directory

That is because "directory" is supposed to be replaced by the directory you want to make the changes in.

As a general idea, if you are offered a script that you don't understand what it's doing, don't run it, ask what a part of it is doing. Otherwise people could tell you to run all kinds of rubbish.
Reply With Quote
  #7  
Old 11-19-2007
Read Only
 

Join Date: Jul 2007
Posts: 15
Just to pass on snippets, here's what I use:

perl -pe 's/\015\012/\n/g' - dos to unix -- just pipe through it
perl -pe 's/\n/\015\012/g' - unix to dos -- just pipe through it

cat filename |perl -pe 's/\015\012/\n/g' > filename.without.ctrl.m

dos2unix works well, but isn't on all systems. I now use this perl.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:27 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0