![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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? |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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........ |
|
#3
|
||||
|
||||
|
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". |
||||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|