![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| grep patterns - File | dhanamurthy | Shell Programming and Scripting | 1 | 05-08-2008 10:24 PM |
| How to get lines in between Patterns? | racbern | Shell Programming and Scripting | 11 | 04-23-2008 07:28 AM |
| 3 patterns in one line | bashuser | UNIX for Advanced & Expert Users | 1 | 02-16-2008 07:02 PM |
| patterns between strings... | pbsrinivas | Shell Programming and Scripting | 6 | 07-12-2007 01:29 PM |
| search patterns | rochitsharma | Shell Programming and Scripting | 1 | 02-27-2006 04:14 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
If the patterns are always on a single line, awk or sed should work fine. If this is a more complex file, look in the Perl FAQ (section 6 IIRC) for some canned solutions.
This is a very frequently recurring question in these forums; try searching some recent threads. Code:
sed -n 's/.*>\([^<>]*\)<.*/\1/p' file |
|
||||
|
Except that will also get anything outside of the separators. And you don't need the parens if you don't use them for backreferences. Anyway, it would be useful to have more precise requirements. Is there text outside of the separators? Do they span multiple lines? Are there other <tags> which are not to be used as separators? Can there be multiple occurrences of the tag pairs on one line?
Code:
sed -n 's%.*<line>%%; T; s%</line>.*%%p' file |
|
||||
|
Quote:
and maybe my sed is too old, I get unrecognized command with sed -n 's%.*<line>%%; T; s%</line>.*%%p' Thanks you file: <b>asdfasdfasdf</b> <line>hello</line> <a>asdfasdfasdf</c> output: hello |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|