The UNIX and Linux Forums  

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


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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help with AWK -- quick question Probos Shell Programming and Scripting 5 07-18-2007 01:26 PM
quick question keith.m AIX 5 12-21-2006 06:27 AM
quick sed question vbm Shell Programming and Scripting 2 11-09-2006 07:44 PM
quick question pkolishetty UNIX for Dummies Questions & Answers 2 09-02-2006 08:56 AM
Ok quick question Corrail Shell Programming and Scripting 1 11-11-2005 10:49 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 04-05-2004
Registered User
 

Join Date: Mar 2004
Posts: 4
quick question

hi guys

trying to understand what this line means

sed is a stream editor and i understand that, i have a file already selected
i want to edit so i use -e

sed -e

the next stesp is s/$*

s is a subsititute replacement

sed -e s/$*/[WORDS DELETED]/g

$ is in reference of the last line
/g makes it global so it would search everything

what does */[WORDS DELETED] do?
Reply With Quote
Forum Sponsor
  #2  
Old 04-05-2004
Registered User
 

Join Date: Feb 2004
Location: netherlands
Posts: 42
Hi,

sed -e s/$*/[WORDS DELETED]/g

The part between the first and second forward slash ($* in the example) is the string to look for. The part between the second and third forward slash ([WORDS DELETED] in the example) is what you want to change it into.

The $ is a refenrence to the end of the line, not the last line (it is not a line range). The example is rather useless because it will search for characters after the end of the line.

The -e option is used if you want to use multiple expressions in sed. Mostly used from within a script.

Example:

sed 's/This/That/g' => Change This into That anywhere on a line.

sed -e 's/Is/Was/g' -e 's/All/None/g' => Change Is in was _and_ All to None, anywhere in the line(s).

Also see:
man sed
http://sed.sourceforge.net/grabbag/tutorials/
http://www.grymoire.com/Unix/Sed.html

Hope this helps.
__________________

The dead stay dead and the living only wait to join them........
Reply With Quote
  #3  
Old 04-06-2004
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,653
This is an extremely confusing and subtle question. It is very easy to get this wrong.

First the dollar sign works differently in sed depending on where it appears.

sed '$d' < /etc/passwd
will print the contents of /etc/passwd, all except the last line. That is an example of $ being used as a line number.

On the other hand:
echo box | sed 's/.*x$/something/'
echo boxes | sed 's/.*x$/something/'
shows the dollar sign anchoring an expression.

But to act as an anchor, the dollar sign must appear as the last character in the expression. Otherwise it becomes a regular character:
echo '$$$$$$$$' | sed 's/$*/something/'

Now in all of these examples, the sed command was enclosed in single quotes. That is not the case in the question. Thus the shell will see $* and probably replace it. Exactly what will happen depends on the shell and the context. I am using ksh:
set one
echo $*
echo one | sed s/$*/something/

The final command will print "something".
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




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


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

Content Relevant URLs by vBSEO 3.2.0