![]() |
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 |
| using awk to extract text between two constant strings | mjoshi | Shell Programming and Scripting | 11 | 03-31-2009 09:37 AM |
| c program to extract text between two delimiters from some text file | kukretiabhi13 | High Level Programming | 7 | 12-03-2008 06:29 PM |
| extract text b/w two delimiters | dowsed4u8 | UNIX for Advanced & Expert Users | 6 | 01-18-2008 05:48 PM |
| How to extract text from xml file | chrisf | Shell Programming and Scripting | 3 | 09-01-2007 02:25 PM |
| How to extract data from a text file | negixx | Shell Programming and Scripting | 1 | 07-19-2005 09:30 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Using awk to extract text
I am currently on a project where I must extract all the data between two words. I am currently running a perl script and trying to use awk to extract specific lines of text between two words: ./myscript.pl | awk ' "
An example of the output of the script: =================== WORKING LOG =================== <----------------------- ------------------------ ------------------------ ------text here--------- ------------------------ ------------------------ -----------------------> =================== I'm trying to use the awk command in the UNIX shell to extract everything between WORKING LOG and the last row of "=" signs. Is there a way to specficy with regexs or in awk syntax to take all the text between two specified points? |
|
||||
|
Expanded and corrected solution
muthukumar's solution almost worked for me and got me on the right track.
I expanded it to multiple lines (I prefer easy-to-read over compact) and got this to work: { if ($0 ~ "text-start") { getline while (! ($0 ~ "text-end")) { if ($0 ~ "text-find") { print FNR, ":", $0 } getline } } } if you put that script in a file called awk-script, then you would invoke it to search a file called text2search as follows: awk -f awk-script text2search it will print out the line #(s) of where it found the search text in between the two tags/marker text. |
![]() |
| Bookmarks |
| Tags |
| perl, perl shift, shift, shift perl |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|