How to check for contrl-M characters


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to check for contrl-M characters
# 1  
Old 08-15-2008
Data How to check for contrl-M characters

Hii

When i am using the following command for checking the ctrl-m characters am getting "Substitution pattern match failed" error.
Actually i jus want to check and not to substitute.
Please suggest me as whats wrong in the below command.

1,$s/Ctrl+vCtrl+m//g

Thanks
ladtony
# 2  
Old 08-15-2008
Probably the application you are using doesn't support using literal control-M:s in regex substitution. Is this sed or vi or some other beast? Is there a reason you don't just run dos2unix or comparable on the file? There is regrettably no single standard portable command which works everywhere, but search this site for "ctrl-m" or "carriage return" or "DOS" or ...
# 3  
Old 08-15-2008
As era said or try out

Code:
cat infile| tr -d '\015' > newfile

Btw., you don't have to explicit address from 1 to $ since if you don't specify an address, it will process the whole input file.
# 4  
Old 08-15-2008
thanks....Zaxxon...
but what is 015 in the command u gave
ladtony
# 5  
Old 08-15-2008
That's the octal value for ^M.

Btw., the better way to write it (saving the cat), correcting myself, is:
Code:
tr -d '\015' < infile > outfile

# 6  
Old 08-15-2008
Just curious, why would you want to just check for? Any purpose for it? :/
# 7  
Old 08-15-2008
i fyou just wanna check for^M char
open the file in vi editor press escape then type /ctrl+vctrl+m
this should work...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To check Blank Lines, Blank Records and Junk Characters in a File

Hi All Need Help I have a file with the below format (ABC.TXT) : ®¿¿ABCDHEJJSJJ|XCBJSKK01|M|7348974982790 HDFLJDKJSKJ|KJALKSD02|M|7378439274898 KJHSAJKHHJJ|LJDSAJKK03|F|9898982039999 (cont......) I need to write a script where it will check for : blank lines (between rows,before... (6 Replies)
Discussion started by: chatwithsaurav
6 Replies

2. Shell Programming and Scripting

ksh check for non printable characters in a string

Hi All, I am trying to find non-printable characters in a string. The sting could have alphanumeric, puntuations and characters like (*&%$#.') but not non-printable (or that is what I think they are called) which are introduced when you copy any text from DOS to unix box. Input string1:... (10 Replies)
Discussion started by: dips_ag
10 Replies

3. Shell Programming and Scripting

Check if the text file has more than 2 characters

Guys, I know that the below command will cut the 13th field from test.txt file awk -F"|" '{print $13}' test.txt The answer would be, CA CN Ohio If we see the 3 rd one, it has more than 2 characters. So i wanted to check this in if condition and i want to get the output if the 13th... (4 Replies)
Discussion started by: AraR87
4 Replies

4. Shell Programming and Scripting

Need HELP with AWK split. Need to check for "special characters" in string before splitting the file

Hi Experts. I'm stuck with the below AWK code where i'm trying to move the records containing any special characters in the last field to a bad file. awk -F, '{if ($NF ~ /^|^/) print >"goodfile";else print >"badfile"}' filename sample data 1,abc,def,1234,A * 2,bed,dec,342,* A ... (6 Replies)
Discussion started by: shell_boy23
6 Replies

5. Shell Programming and Scripting

sed replacing specific characters and control characters by escaping

sed -e "s// /g" old.txt > new.txt While I do know some control characters need to be escaped, can normal characters also be escaped and still work the same way? Basically I do not know all control characters that have a special meaning, for example, ?, ., % have a meaning and have to be escaped... (11 Replies)
Discussion started by: ijustneeda
11 Replies

6. Homework & Coursework Questions

Check 2 variables for matching characters

hi i am writing a hangman script and am having trouble checking the correct letters against the word i need the script to compare the word against the letters guessed that are correct so once all the letters within the word have been guessed it will alow me to create a wining senario this must... (1 Reply)
Discussion started by: lsecer
1 Replies

7. Shell Programming and Scripting

Check input for lenght, special characters and letter case

I made menu script for users so they can run other script without going in shell just from menu. But i must control their input. These are criteria: Input must have 4 signs First two signs are always lower case letters Input shall not have some special signs just letters and numbers ... (1 Reply)
Discussion started by: waso
1 Replies

8. Shell Programming and Scripting

How to check if the file has EBCDIC or ascii characters

Hi, is there a way to check if the initial few characters are ebcdic or ascii in a file? (1 Reply)
Discussion started by: ahmedwaseem2000
1 Replies

9. UNIX for Advanced & Expert Users

Execute All Commands in A contrl File

Hi , I have a situation i need to write a while loop until the end of control file.In the control file i have a 5 lines which contains commands.how can i execute all with out waiting for the first one to complete. Ex ControlFile: ScripitName Test ScriptName Test1 ScriptName Test2 ... (1 Reply)
Discussion started by: ukatru
1 Replies

10. Shell Programming and Scripting

Check for special characters in a script

Hi All, In my shell script, i'm checking the date input against few constraints. It should be of YYYYMMDD format and the script should prompt the user with error message, if less than 8 digits are present or input contains special characters (*,&,%,^,$ ...etc). The script i'm using is given... (7 Replies)
Discussion started by: sumesh.abraham
7 Replies
Login or Register to Ask a Question