Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-27-2012
Registered User
 
Join Date: May 2011
Posts: 190
Thanks: 92
Thanked 0 Times in 0 Posts
Using sed to replace / in text file

Hi,

I want to use sed to replace " /// " with "///" in a text file. However I am getting error messages when I use
PHP Code:
sed 's/ /// /////g' input.txt output.txt 
. How do I go about doing this in sed?

Input:

Code:
219518_s_at 0.000189 ELL3 / SERINC4

Output:

Code:
219518_s_at 0.000189 ELL3/SERINC4

Sponsored Links
    #2  
Old 06-27-2012
...@...
 
Join Date: Feb 2004
Location: NM
Posts: 9,658
Thanks: 164
Thanked 646 Times in 623 Posts

Code:
sed 's/ \/ /\//g' infile >outfile

The Following User Says Thank You to jim mcnamara For This Useful Post:
evelibertine (06-27-2012)
Sponsored Links
    #3  
Old 06-27-2012
Registered User
 
Join Date: May 2011
Posts: 190
Thanks: 92
Thanked 0 Times in 0 Posts
Sorry about the confusion, the smaple input should have been:


Code:
219518_s_at 0.000189 ELL3 /// SERINC4

and the sample output:


Code:
219518_s_at 0.000189 ELL3/SERINC4

Thanks!
    #4  
Old 06-28-2012
Registered User
 
Join Date: Mar 2012
Posts: 18
Thanks: 8
Thanked 1 Time in 1 Post
You can use a ':' in place of a '/' to avoid confusions.


Code:
 
sed 's: ///:///:g' input.txt > output.txt  

The Following User Says Thank You to prithvirao17 For This Useful Post:
evelibertine (09-11-2012)
Sponsored Links
    #5  
Old 06-28-2012
jayan_jay's Avatar
Forum Advisor
 
Join Date: Jul 2008
Posts: 831
Thanks: 9
Thanked 185 Times in 176 Posts

Code:
$ sed 's, /// ,/,g' infile

The Following User Says Thank You to jayan_jay For This Useful Post:
evelibertine (09-11-2012)
Sponsored Links
    #6  
Old 06-28-2012
Scrutinizer's Avatar
Moderator
 
Join Date: Nov 2008
Location: Amsterdam
Posts: 7,350
Thanks: 144
Thanked 1,756 Times in 1,593 Posts

Code:
sed 's| *//* *|/|g'

The Following User Says Thank You to Scrutinizer For This Useful Post:
evelibertine (09-11-2012)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replace char on text file phillipss Shell Programming and Scripting 2 12-11-2010 12:19 AM
search and replace a text in a file goutam_igate Shell Programming and Scripting 5 04-27-2009 06:03 AM
How to replace text in a file with text entered cleanden Shell Programming and Scripting 9 04-11-2009 08:03 PM
how can search a String in one text file and replace the whole line in another file kkraja UNIX for Dummies Questions & Answers 6 08-06-2008 07:23 AM
search and replace a specific text in text file? santosham UNIX for Dummies Questions & Answers 4 06-25-2008 05:53 PM



All times are GMT -4. The time now is 10:18 PM.