The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
removing comments from file skully Shell Programming and Scripting 9 06-08-2008 09:44 PM
Removing a file name (-T-G1) bobo UNIX for Dummies Questions & Answers 3 03-05-2008 11:26 AM
Need Help Removing a File GTRocker8824 UNIX for Dummies Questions & Answers 1 02-15-2008 12:04 AM
removing a line from a file and then placing into another file iago UNIX for Dummies Questions & Answers 1 09-09-2007 01:46 AM
removing file vbaskar UNIX for Advanced & Expert Users 5 02-12-2002 04:43 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 10-09-2008
JamesByars JamesByars is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 124
removing the last , in a file

hi,

I have a file that contains one line with , at the end of it and I want to remove it using sed

I tried

s/,$//g

but it does not work

thanks
  #2 (permalink)  
Old 10-09-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink switch the order of your argument values

Code:
> cat file2
abc 1234 def
lmn 4567 xyz,
qrs 5689 mou
> sed "s/,$//g" <file2
abc 1234 def
lmn 4567 xyz
qrs 5689 mou
>
$ anchors to end of a line
^ anchors beginning of a line
  #3 (permalink)  
Old 10-09-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,953
Code:
> sed "s/,$//g" <file2
I think -g is not needed here
  #4 (permalink)  
Old 10-09-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink You are correct - force of habit to always use the 'g'

Quote:
matrixmadhan --
I think -g is not needed here
The 'g' in the command is extra as there can only be one instance per line. Command should simply be:

Code:
>sed "s/,$//" <file2
  #5 (permalink)  
Old 10-09-2008
lucaxvu lucaxvu is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 2
Awk

cat file2 | awk -F, '{ print }'
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 08:22 AM.


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