The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
replace a character with another character satish@123 Shell Programming and Scripting 8 05-13-2009 04:04 PM
Replace certain character with a new a new line. djsal Shell Programming and Scripting 8 01-11-2008 12:59 PM
to replace a new line character chan Shell Programming and Scripting 2 01-11-2008 12:56 PM
replace character with tr tmxps UNIX for Dummies Questions & Answers 3 09-29-2005 08:32 AM
How would I replace the 9th character of every line in a file? LordJezo Shell Programming and Scripting 5 09-01-2004 12:51 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-01-2007
Mohammed Mohammed is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 12
Replace a character in last line

Hello Sed Experts,

I have got a file which contain entries as below
pmNoOfSwDownHsCong,
pmUlUpswitchAttemptHigh,
pmUlUpswitchAttemptLow,
pmUlUpswitchSuccessHigh,
pmUlUpswitchSuccessLow,
pmUpswitchFachHsAttempt,
pmUpswitchFachHsSuccess,

I want to replace the the comma "," in the last line with a space.

Can you please help me with this in sed

Thanks a lot in advance

Mohammed
  #2 (permalink)  
Old 08-01-2007
ahmedwaseem2000 ahmedwaseem2000 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Bangalore
Posts: 219
try this:


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

  #3 (permalink)  
Old 08-01-2007
matrixmadhan matrixmadhan is online now Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,958
Quote:
Originally Posted by ahmedwaseem2000 View Post
try this:


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

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

you don't have to escape ' , ' character
  #4 (permalink)  
Old 08-01-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
On a side note, there is no need for 'g' at the end of the 's' command.

The 'g' option replaces all instances of the string in the same line.

In this specific case, the OP says and shows that there is only one ',' (comma).

Also, the solutions remove the comma -- the OP is asking the comma to be replaced
by space:

Code:
sed '$s/,/ /' input_file

  #5 (permalink)  
Old 08-01-2007
matrixmadhan matrixmadhan is online now Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,958
That's a cool catch !

Usually for these kind of formatting where we would be mostly interested in removing the last occurring ' , ' character ( in most of the cases if its there which doesn't add meaning )

But anyway I should have been attentive !
  #6 (permalink)  
Old 08-01-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,555
Quote:
Originally Posted by Mohammed View Post
I want to replace the the comma "," in the last line with a space.
this may mean only the last line.
  #7 (permalink)  
Old 08-01-2007
ahmedwaseem2000 ahmedwaseem2000 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Bangalore
Posts: 219
Well, I am into the habit of making the replacement global. and does any one have the list of characters which has to be escaped? I suggested that because i didnt had the unix box to cross check that. Nevermind, thanks for the corrections
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:04 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0