The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
find and replace string in a directory files koti_rama Shell Programming and Scripting 2 05-30-2008 12:48 AM
shell script to find and replace string in multiple files pharos467 Shell Programming and Scripting 10 05-20-2008 08:39 AM
Find and replace character in a string callimaco0082 UNIX for Dummies Questions & Answers 7 04-10-2008 07:47 AM
How to replace all string instances found by find+grep umen Shell Programming and Scripting 0 12-05-2007 11:52 PM
Find and replace a string in multiple files pharos467 UNIX for Dummies Questions & Answers 2 11-05-2007 07:47 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-16-2006
Registered User
 

Join Date: Sep 2005
Posts: 20
Stumble this Post!
how to find and replace string

hi
I wanted to find this char " ^M " in my file and replace it with blank space.
I am using Unix system.
If i give command " :%s/^M//gc " it wont work
so can anyone tell what is command to find and replace


thankx
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-16-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,660
Stumble this Post!
Quote:
Originally Posted by mridula
hi
I wanted to find this char " ^M " in my file and replace it with blank space.
I am using Unix system.
If i give command " :%s/^M//gc " it wont work
so can anyone tell what is command to find and replace


thankx
You have posted in the "C Programming..." forum. But seeing your command it is actually a non C programming question.

Run dos2unix on the file before you view it i.e. dos2unix input.txt
Reply With Quote
  #3 (permalink)  
Old 08-17-2006
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,572
Stumble this Post!
Quote:
Originally Posted by mridula
hi
I wanted to find this char " ^M " in my file and replace it with blank space.
I am using Unix system.
If i give command " :%s/^M//gc " it wont work
so can anyone tell what is command to find and replace


thankx
i suppose the ^M character issued in replace mode is done by typing ctrl-v + ctrl-m -- then it would work definitely.
Reply With Quote
  #4 (permalink)  
Old 08-17-2006
Registered User
 

Join Date: May 2006
Posts: 95
Stumble this Post!
cat file | tr "\r" " " >outfile

in C <pseudocode>:
fd=open()
loop:
read(fd,buf,1)
if (buf== ^M) buf =' '
write(fileno_stdout,buf,1);
clsoe(fd);
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:25 PM.


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

Content Relevant URLs by vBSEO 3.2.0