How to strip ^M at end of each files for all files found in current directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to strip ^M at end of each files for all files found in current directory
# 1  
Old 06-18-2009
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  
Old 06-18-2009
What is your OS ?

Code:
uname -a

# 3  
Old 06-18-2009
Aix 5.3
# 4  
Old 06-18-2009
Quote:
Originally Posted by bisip99
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  
Old 06-18-2009
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unzip Multiple zip files and Strip directory

I receive multiple zipped directories with files in them, so the .zip name is the name of the directory containing the files. so i have used a simple loop to unzip all of them but when unzipped i have folders/directories, i wanted to strip these directories and remain with the actual files from... (1 Reply)
Discussion started by: buggzdiq
1 Replies

2. UNIX for Advanced & Expert Users

Find all files in the current directory excluding hidden files and directories

Find all files in the current directory only excluding hidden directories and files. For the below command, though it's not deleting hidden files.. it is traversing through the hidden directories and listing normal which should be avoided. `find . \( ! -name ".*" -prune \) -mtime +${n_days}... (7 Replies)
Discussion started by: ksailesh1
7 Replies

3. Shell Programming and Scripting

Find files only in current directory...not subdirectories

Hi, I have to find files only in the current directory...not in the sub directories. But when I use Find command ... it searches all the files in the current directory as well as in the subdirectories. I am using AIX-UNIX machine.Please help..I tried to use maxdepth..but it is not working in AIX. (2 Replies)
Discussion started by: vsachan
2 Replies

4. HP-UX

How do I include header files outside of my current directory

I am trying to compile a file called PPFormatageMUT.c in which I have included header file which are at some other location but the point is that while compiling the file, it is throwing error saying that error : no such file or directory source code location:... (1 Reply)
Discussion started by: ezee
1 Replies

5. Shell Programming and Scripting

Find files ONLY in current directory

Hello all, I am having a hard type in figuring out how to only gather certain files in the current directory without exploring its subdirectories. I tried: find . -name "*.ksh" -prune this also returns ksh files from lower subdirectories. I also tried find . -ls -name "*.ksh" This also... (8 Replies)
Discussion started by: gio001
8 Replies

6. Shell Programming and Scripting

mget * (obtein files from current directory but not the files form sub-directories)

Hello, Using the instruction mget (within ftp) and with "Interactive mode off", I want to get all files from directory (DirAA), but not the files in sub-directories. The files names don't follow any defined rule, so they can be just letters without (.) period Directory structure example: ... (0 Replies)
Discussion started by: Peter321
0 Replies

7. Shell Programming and Scripting

Finding files in current directory when 100,000's files in current directory

Hi All I was wondering what is the most efficient way to find files in the current directory(that may contain 100,000's files), that meets a certain specified file type and of a certain age. I have experimented with the find command in unix but it also searches all sub directories. I have... (2 Replies)
Discussion started by: kewong007
2 Replies

8. UNIX for Dummies Questions & Answers

List files that are not directories from current directory

I can't manage to list all files that are not directories from current directory. (2 Replies)
Discussion started by: beni22sof
2 Replies

9. Shell Programming and Scripting

finding 0 byte files in current directory only

Hi Gurus, I have a directory A, which has some 0 byte files in it. This directory also has a subdirectory B which also has some 0 byte files in it. The problem: I only need to find out the names of the 0 byte files in the directory A. I'm using the following command find . -name *.zip... (6 Replies)
Discussion started by: ramky79
6 Replies

10. Shell Programming and Scripting

Searching for files over 30 days old in current directory

May be a simple question for experts here.... I need to get the list of files older than 30 days in the current folder. I tried "find", but it searches recursively in all the sub directories. Can I restrict the recursive search and extract the files only from current directory ? (18 Replies)
Discussion started by: cxredd4
18 Replies
Login or Register to Ask a Question