![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| doubt in tr command | risshanth | UNIX for Dummies Questions & Answers | 2 | 02-25-2008 07:20 AM |
| doubt in AWK | abnirmal | Shell Programming and Scripting | 4 | 05-08-2007 02:27 PM |
| Pls help for the doubt | ravi.sadani19 | Shell Programming and Scripting | 4 | 04-12-2007 01:51 AM |
| doubt in cal command | sumi | AIX | 9 | 03-03-2006 09:33 AM |
| Doubt in find command | mona | Shell Programming and Scripting | 3 | 12-11-2005 09:54 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Doubt in SED command
PLEASE EXPLANIN ME...
sed 's~\(.*\)\(<name>\)\(.*\)\(</name>\)\(.*\)~\2\3\4~' this is the format <start><name>123<\name><addr>BAC<\addr><loc>sfo<\loc></start> |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Quote:
<name> literally the string </name> literally the string Find lines with "<name>" and "</name>", where "<name>" can preceded by any amount of characters, "</name>" can be followed by any amount of characters, and there can be any amount of characters in between "<name>" and "</name>" \(.....\) whatever is found put in a buffer, subsequent \(.....\) means put in next buffer. 1st \(.*\) will match "<start>" and this string will be placed in buffer 1 \(<name>\) will match "<name>" and this string will be placed in buffer 2 2nd \(.*\) will match "123" and this string will be placed in buffer 3 \(</name>\) will match "</name>" and this string will be placed in buffer 4 \(.*\) will match "<addr>BAC<\addr><loc>sfo<\loc></start>" and this string will be placed in buffer 5. "~" is used in the sed instead of "/" so the "/" in "</name>" doesnt need to be escaped. If a line is found which matches the patterns, replace them by what ever is in buffer 2,3 and 4. So based on the string given: <start><name>123<\name><addr>BAC<\addr><loc>sfo<\loc></start> The result of the sed command: sed 's~\(.*\)\(<name>\)\(.*\)\(</name>\)\(.*\)~\2\3\4~' will be: <name>123<\name> Shorter: sed 's~.*\(<name>\)\(.*\)\(</name>\).*~\1\2\3~' With "/" instead of "~": sed 's/.*\(<name>\)\(.*\)\(<\/name>\).*/\1\2\3/' |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|