The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
extract a particular start and end pattern from a line manish205 Shell Programming and Scripting 7 02-07-2008 06:18 AM
Extract Pattern Sequence jaganadh Shell Programming and Scripting 5 12-10-2007 11:06 AM
Extract if pattern matches Raynon Shell Programming and Scripting 20 10-29-2007 04:44 AM
Extract the Pattern aajan UNIX for Dummies Questions & Answers 6 08-08-2007 05:47 AM
Please help! Sed extract a pattern zhen Shell Programming and Scripting 11 09-18-2006 01:36 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-02-2006
npn35 npn35 is offline
Registered User
  
 

Join Date: May 2005
Posts: 12
awk: need to extract a line before a pattern

Hello ,

I need your help to extract a line in a big file , and this line is always 11 lines
before a specific pattern . Do you know a way via Awk ?

Thanks in advance

npn35
  #2 (permalink)  
Old 08-02-2006
nilesrex nilesrex is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 43
mate try this,

awk 'BEGIN {}^J{ if( NR == 11 ) print $0 };^JEND{} ' datafile

Cheers,
  #3 (permalink)  
Old 08-02-2006
npn35 npn35 is offline
Registered User
  
 

Join Date: May 2005
Posts: 12
Quote:
Originally Posted by nilesrex
mate try this,

awk 'BEGIN {}^J{ if( NR == 11 ) print $0 };^JEND{} ' datafile

Cheers,

In fact , I don't want to print the line 11 . I need to search for a specific pattern
then print the line NR-11 .
I hope my explanation is better .

Thanks.
BR
  #4 (permalink)  
Old 08-02-2006
suman_jakkula suman_jakkula is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 35
Try this...

/pattern/ && NR == 11 {
print $0;
}
  #5 (permalink)  
Old 08-02-2006
npn35 npn35 is offline
Registered User
  
 

Join Date: May 2005
Posts: 12
Quote:
Originally Posted by suman_jakkula
Try this...

/pattern/ && NR == 11 {
print $0;
}
Thanks but the pattern is not located on line 11 . I want to print the line
which is 11 lines before the pattern .

Regards
npn35
  #6 (permalink)  
Old 08-02-2006
xinusys xinusys is offline
Registered User
  
 

Join Date: May 2006
Posts: 13
Smile Hi

hey man u r not so clearabout what u want?cleat itmate.then it would be easier to give u thesolution.
  #7 (permalink)  
Old 06-26-2008
kvaibhav kvaibhav is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 2
I want this

I a file with lines containing 3 columns each,

If column 3 of a line is zero, then
substract the second entry of present column from
the second entry of the prvious column.

e.g.

28 -4.8743 2
29 -4.8726 2
30 -4.7833 2
31 -4.7721 2
32 -4.7690 2
33 -4.6266 2
34 -4.6203 2
35 -3.8990 1
36 -3.2009 0

37 -2.9944 0
38 -2.9934 0
39 -2.8856 0
40 -2.8820 0

then it should subtract -3.2009 from -3.8990 and give me the answer.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:19 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0