Find ^M Character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find ^M Character
# 1  
Old 10-21-2009
Find ^M Character

Hi Experts,

Is there a way to find whether a file contains ^M character in it?. It's quite obvious to vi, but can this be accomplished using an automated way to find recursively in a directory.

probably i guess the best way would be to

1) Read the file and check if the end of line is ^M
2) If so, then echo saying the file has ^M character
3) Else not

pls correct me if i am wrong
# 2  
Old 10-21-2009
Code:
find . -type f -exec grep -l "^M" {} \;

(the control-m (^M) in the grep is acquired by pressing control-v then control-m - i.e. don't cut and paste the above code, because it won't give you the desired result!)
# 3  
Old 10-21-2009
so what are you going to do after finding there are ^M characters? Ultimately, do you want to remove them? if yes, use the find command together with dos2unix.
# 4  
Old 10-21-2009
thanks much ghostdog74.. yes that's the ultimate goal.. i wud do sed 's/\r//' filename >filename.new
# 5  
Old 10-21-2009
Quote:
Originally Posted by ganga.dharan
thanks much ghostdog74.. yes that's the ultimate goal.. i wud do sed 's/\r//' filename >filename.new
if you have dos2unix, use it. its easier than crafting your own regex.
# 6  
Old 10-21-2009
but i don't :-(
# 7  
Old 10-21-2009
Use tr:

Code:
tr -d '\r' < dosfile > unixfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find invalid character

HI Team, I have script to find the invalid character in file. f=’pallvi\mahajan’ n=0 while (( $n <= ${#f} )); do c="${f:$n:1}" echo '$c' if *] ]]; then grep -sq $c valid.txt if ; then echo "$f" >> f.txt break fi fi (18 Replies)
Discussion started by: pallvi_mahajan
18 Replies

2. Shell Programming and Scripting

Find character and Replace character for given position

Hi, i want find the character '-' in a file from position 284-298, if it occurs i need to replace it with 'O ' for the position in the file. How to do that using SED command. thanks in advance, Sara (9 Replies)
Discussion started by: Sara183
9 Replies

3. UNIX for Dummies Questions & Answers

Find certain number of character in vi

Hello, Experts, I have a file with the first and second column connected together, and i want to use vi to seperate them (put a space in between). Is there any command in vi would put a space after the 7th letter? Thanks! example: 0.981101.517 2.944101.517 4.907101.517 (10 Replies)
Discussion started by: wingsy1212
10 Replies

4. Shell Programming and Scripting

How to find character position in file?

how to find character positionin file? i.e string = "123X568" i want to find the position of character "X". Thanks (6 Replies)
Discussion started by: LiorAmitai
6 Replies

5. Shell Programming and Scripting

Find and replace a character

Hi Team, i have 1st cloumn of data containing, LAMSBA01-BA-COFF-YTD LAMSBA01-BA-COFF-ITD LAMSBA01-BA-AGGR-IND . LAMSBA01-BA-CURR-COFF-BAL i need to replace the "-" to "_" (underscore) using AWK . please help me on this. Thanks, Baski (4 Replies)
Discussion started by: baskivs
4 Replies

6. UNIX for Dummies Questions & Answers

to find alphanumeric character

Hi All, I am having a data file which consists of lakhs of records in the below foramt: "1223323","4341341","discription aadfad" "3123123","5463456","discription aadfad" "2343324","6565767","discription asdfads" "A3423423","7957456","discription aadfad" "343453B","7957456","discription... (1 Reply)
Discussion started by: abhi_123
1 Replies

7. Shell Programming and Scripting

To find a character immediately following a word

Hello, I have data in one file like - UNB+UNOA:1+006415160:1+WF0000010188:ZZ+080701:0600+2++DELFOR++++T'UNH+2+DELFOR:D:97A:UN................ Now, I want to find what is the character immediately following UNB(here +) UNOA (here :) or the character immedialtely preceding UNH (here ') &... (2 Replies)
Discussion started by: The Observer
2 Replies

8. Shell Programming and Scripting

Find Unicode Character in File

I have a very large file in Unix that I would like to search for all instances of the unicode character 0x17. I need to remove these characters because the character is causing my SAX Parser to throw an exception. Does anyone know how to find a unicode character in a file? Thank you for your... (1 Reply)
Discussion started by: azelinsk
1 Replies

9. UNIX for Dummies Questions & Answers

Find and replace character in a string

Hi all, My problem is the following: I've a script that must list all files in a directory and write this information in a text file. I've tried to get the list through ls command and then write it using msgecho msgecho "`ls $PATH_APS_JOB_ORA`" This works good but the created string... (7 Replies)
Discussion started by: callimaco0082
7 Replies

10. Shell Programming and Scripting

How to find EOF character in a Shell ?

Hi, I'm need to determine if a file contains the EOF character, how can I do that in Shell scripting? Regards. (1 Reply)
Discussion started by: jfortes
1 Replies
Login or Register to Ask a Question