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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Find files ONLY in current directory gio001 Shell Programming and Scripting 8 06-19-2009 07:58 AM
mget * (obtein files from current directory but not the files form sub-directories) Peter321 Shell Programming and Scripting 0 03-12-2009 11:59 AM
Finding files in current directory when 100,000's files in current directory kewong007 Shell Programming and Scripting 2 02-26-2009 03:13 PM
List files that are not directories from current directory beni22sof UNIX for Dummies Questions & Answers 2 01-06-2009 03:44 PM
Searching for files over 30 days old in current directory cxredd4 Shell Programming and Scripting 18 06-11-2006 03:16 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-18-2009
bisip99 bisip99 is offline
Registered User
  
 

Join Date: Jun 2009
Location: Canada
Posts: 3
Question How to strip ^M at end of each files for all files found in current directory

I am trying to use a loop to strip of the funny character ^M at the end of all lines in each file found in current directory and I have used the following in a script:

find . -type f -name '*.txt' | while read file
do
echo "stripping ^M from [$file]..."
ex - "$file" > $tempfile
%s/^M//g
wq!
# mv -i "$tempfile" > "$file"
done;

I got the following error messages instead:

0602-004 The specified address is not valid.
ex: 0602-004 The specified address is not valid.
teststrip[11]: %s/^M//g: not found.
teststrip[12]: wq!: not found.

Can anyone help please?

Appreciate much!
  #2 (permalink)  
Old 06-18-2009
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321
What is your OS ?


Code:
uname -a

  #3 (permalink)  
Old 06-18-2009
bisip99 bisip99 is offline
Registered User
  
 

Join Date: Jun 2009
Location: Canada
Posts: 3
Aix 5.3
  #4 (permalink)  
Old 06-18-2009
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321
Quote:
Originally Posted by bisip99 View Post
Aix 5.3

OK, try sed instead:



Code:
 find . -type f -name '*.txt' | 
	while read file
	 do
           sed 's/^M$//' "$file" > "$file".tmp && mv "$file".tmp "$file"
         done

To enter ^M inside the sed statement, press CTRL+V then ENTER.
  #5 (permalink)  
Old 06-18-2009
King Kalyan King Kalyan is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 12
Try this..


Code:
 
find . -type f -name '*.txt' | while read file
do
echo "stripping ^M from [$file]..."
sed "s/^M//g" file > temp_file
mv -f temp_file > file
done

Note: For ^M do not directly type cap (^) and letter M - use "CNTRL+V and then press enter" you will get ^M character.
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0