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



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 !!

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-03-2012
Registered User
 

Join Date: Sep 2011
Posts: 25
Thanks: 4
Thanked 0 Times in 0 Posts
Clarification required on sed

Hi

Can some one tell what does this sed command do


sed 's/[]*[]$//g

I am more curious on the highlighted part , can some one explain what does that mean.

Thanks
Sri
Sponsored Links
    #2  
Old 02-03-2012
Registered User
 

Join Date: Mar 2011
Posts: 547
Thanks: 35
Thanked 135 Times in 131 Posts
The final $ is an anchor, means end of the line. That's easy. Now the outer brackets:

Code:
[]*[]

mean "match any one of these characters".
E.g., if you have [abd], it will match any of the chars 'a', 'b', 'd'.
So the whole thing will strip (substitute with empty string) any trailing ],[,or * on the line (only one character).
'g' is unnecessary, because of the $ anchor, you cannot substitute any further.
And to make this syntactically correct, we need a closing single quote also.
Here:

Code:
$ echo 'sfj[dd]aa[][]*sd[667]qf[[]]*[]' | sed 's/[]*[]$//'
sfj[dd]aa[][]*sd[667]qf[[]]*[

To strip all the trailing ],[, or *, you just an *, quantifier:

Code:
$ echo 'sfj[dd]aa[][]*sd[667]qf[[]]*[]' | sed 's/[]*[]*$//'
sfj[dd]aa[][]*sd[667]qf


Last edited by mirni; 02-03-2012 at 03:41 AM.. Reason: added example
Sponsored Links
Reply

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
clarification Required in Write command little_wonder Shell Programming and Scripting 3 02-01-2010 09:04 PM
Getting required fields from a test file in required fromat in unix rdhanek Shell Programming and Scripting 7 07-22-2009 11:35 AM
Clarification Shahul Web Programming 1 08-16-2008 04:05 AM
Script required to get a required info from file. Pls. help me. ntgobinath Shell Programming and Scripting 2 05-31-2008 08:34 AM
Need clarification ravi.sadani19 Shell Programming and Scripting 2 04-13-2007 01:55 AM



All times are GMT -4. The time now is 03:36 AM.