![]() |
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 |
| confused | sauravjung | UNIX for Dummies Questions & Answers | 1 | 04-07-2008 10:08 AM |
| confused with cp | C|[anti-trust] | Shell Programming and Scripting | 12 | 05-26-2005 12:55 AM |
| confused about tar | frustrated1 | SUN Solaris | 5 | 06-24-2004 10:50 AM |
| confused | hapiworm | UNIX for Dummies Questions & Answers | 4 | 06-17-2002 02:30 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
sed very confused
Hello experts,
I have this complicated code that output value in between pattern and add "a string" to the front of the output. The problems I have many pattern that are the same. so I want to know how to get the value between 1st pattern, 2nd pattern etc. Any suggestions? sed -n '/<pattern>/s/.*>\(.*\)<.*/a string\1/gp' file file: <Pattern>file<\Pattern> <Pattern>file2<\Pattern> .. <Pattern>file3<\Pattern> .. <Pattern>file4<\Pattern> sed -n '/<pattern>/s/.*>\(.*\)<.*/string=\1/gp' file returns: string=file string=file2 string=file3 string=file4 but I want a sed command that gets only the value between the 3rd occurrence of pattern string=file3 Last edited by minifish; 04-11-2008 at 05:04 PM.. |
|
||||
|
ok
so file: <Pattern>file<\Pattern> <Pattern>file2<\Pattern> .. <Pattern>file3<\Pattern> .. <Pattern>file4<\Pattern> sed -n '/<pattern>/s/.*>\(.*\)<.*/string=\1/gp' file returns: string=file string=file2 string=file3 string=file4 but I want a sed command that gets only the value between the 3rd occurrence of pattern string=file3 Last edited by minifish; 04-11-2008 at 04:34 PM.. |
|
||||
|
hm.. I tried this one before, it output all values up to the 1st pattern.
so file: <before>blah<\before> <before>blah1<\before> <before>blah2<\before> <Pattern>file<\Pattern> .. <Pattern>file2<\Pattern> outputs: string=blah string=blah1 string=blah2 string=file |
|
||||
|
Code:
awk 'BEGIN{FS="<|>"}/<Pattern>/{c++}c==3{print "string="$3}' file
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|