![]() |
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 |
| find pattern, delete line with pattern and line above and line below | nickg | Shell Programming and Scripting | 4 | 01-29-2009 01:38 PM |
| Extract pattern from text line | TehOne | Shell Programming and Scripting | 4 | 12-25-2008 01:25 PM |
| Extract pattern from text line | TehOne | Shell Programming and Scripting | 3 | 10-15-2008 01:46 PM |
| Extract pattern from text line | vampirodolce | Shell Programming and Scripting | 9 | 10-14-2008 12:17 PM |
| extract a particular start and end pattern from a line | manish205 | Shell Programming and Scripting | 7 | 02-07-2008 06:18 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
sed: Find start of pattern and extract text to end of line, including the pattern
This is my first post, please be nice. I have tried to google and read different tutorials.
The task at hand is: Input file input.txt (example) abc123defhij-E-1234jslo 456ujs-W-abXjklp From this file the task is to grep the -E- and -W- strings that are unique and write a new file starting with the matched pattern (-E-, -W-) The end result should look like this: -E-1234jslo -W-abXjklp The closest I have come to do this is using this code: Code:
grep -e '-[EW]-' input.txt | sed 's/.*'-[EW]-'//' 1234jslo abXjklp The problem is that this doesn't give me the -E- and -W- that is part of the regular expression. I guess I need a way to put in the matched part into the replace part of sed. Thanks in advance for any help. Last edited by TestTomas; 05-27-2009 at 10:33 AM.. Reason: Corrected spelling error |
|
||||
|
It did the trick, thank you very, very much
![]() Edit: Actually the pure sed-version 'fixed' the lines with the matching pattern but also printed out all non matching lines while the version with grep worked perfectly Last edited by TestTomas; 05-27-2009 at 11:55 AM.. Reason: Extended the information. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|