![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | 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 !! |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
sed question
Hi, can anyone explain step by step what this line of sed code is trying to do. Thanks.
Sed -e "s/big \(.*\) dog/small \1 cat/" filename Last edited by NycUnxer; 10-04-2007 at 09:04 AM. |
| Forum Sponsor | ||
|
|
|
|||
|
Quote:
this is the not the way it works Code:
echo "a big black dog" | sed -e 's/big \(.*\) dog/small \1 cat/' a small black cat Code:
echo "a big black eared dog" |
|
|||
|
Sed -e "s/big \(.*\) dog/small \1 cat/" filename
Explanations: 1> -e - is used when using multiple replacements usinf regular expressions or not 2> you are searching for "big" and "anything after that" and then "dog" 3> you are replacing "big" with "small" and "dog" with "cat" without deterioriating the "anything after that" text when sed searches, it remembers the \(.*\) and it can be accessed using \1. hope this helps. Cheers, Devaraj Takhellambam |
| Tags |
| regex, regular expressions |
| Thread Tools | |
| Display Modes | |
|
|