![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| c program to extract text between two delimiters from some text file | kukretiabhi13 | High Level Programming | 7 | 1 Day Ago 03:29 PM |
| Using awk to extract text | Davizzle | Shell Programming and Scripting | 5 | 08-14-2008 10:09 PM |
| replacing strings with text from other file | mc1392 | Shell Programming and Scripting | 1 | 03-24-2008 12:46 PM |
| extracting a set of strings from a text file | Deanne | Shell Programming and Scripting | 2 | 09-20-2007 08:31 PM |
| How to extract text from xml file | chrisf | Shell Programming and Scripting | 3 | 09-01-2007 11:25 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
using awk to extract text between two constant strings
Hi,
I have a file from which i need to extract data between two constant strings. The data looks like this : Line 1 SUN> read db @cmpd unit 60 Line 2 Parameter: CMPD -> "C00071" Line 3 Line 4 SUN> generate Line 5 tabint>ERROR: (Variable data) The data i need to extract is Line 2 but only when Line 1 is "SUN> read db @cmpd unit 60" and Line 5 is "tabint>ERROR:" The following cant print Line 2, moreover i am specific that my start and end string belong to line i and i+4. awk '/SUN> read db @cmpd unit 60/,/tabint>ERROR/ {print}' database_energy.out > tf4 Any help will be greatly appreciated. -Manali |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
In other words what i want to do is the following:
if row number "i" = /SUN> read db @cmpd unit 60/ and row number "i+4" = /tabint>ERROR:/ print row number "i+1" |
|
#3
|
|||
|
|||
|
IF the file REALLY has "Line 1", etc. in it:
Code:
awk ' arr[$1 $2]=$0
if(arr[$1 $2]=="Line5" &&
arr["Line1"]=="SUN> read db @cmpd unit 60" &&
arr["Line5"]=="tabint>ERROR:")
{
print arr["Line2"]
}
' inputfilename
|
|
#4
|
|||
|
|||
|
I'm sorry i wrote those Line numbers to explain what i wanted to do.
What i would like to do is if row number "i" = /SUN> read db @cmpd unit 60/ and row number "i+4" = /tabint>ERROR:/ print row number "i+1" |
|
#5
|
|||
|
|||
|
Try this:
Code:
awk '
/^SUN> read db @cmpd unit 60/ || c {
c++
if(c==2) {
var=$0
}
if(c==5 && /^tabint>ERROR:.*/) {
print var
c=0
}
}' file
Regards |
|
#6
|
||||
|
||||
|
Code:
awk '/SUN> read db @cmpd unit 60/ {c = 3; getline; s = $0 }
!c-- && /tabint>ERROR:/ { print s }' input
|
|
#7
|
|||
|
|||
|
Quote:
Code:
[n]awk '/SUN> read db @cmpd unit 60/,/tabint>ERROR:/ {
if (last_line == "SUN> read db @cmpd unit 60")
print
last_line = $0
}' file
|
|||
| Google The UNIX and Linux Forums |