The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
check position of end of line(URGENT PLS) evvander Shell Programming and Scripting 6 11-11-2007 05:46 PM
check position of end of line for some specific lines senthil_is Shell Programming and Scripting 1 11-09-2007 01:19 AM
Check last line with gawk? sjf Shell Programming and Scripting 3 10-04-2006 02:20 AM
Script to check for a file, check for 2hrs. then quit mmarsh UNIX for Dummies Questions & Answers 2 09-16-2005 02:46 PM
How to check the number of command line arguments? prkwan Shell Programming and Scripting 3 11-17-2002 01:57 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 11-25-2006
fongthai fongthai is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 54
check line in a file

Hi all,

How do we check in a file whether a line started with KEYWORD2 is right after the line started with KEYWORD1

for example, this file content:

Abcdef gsh iasdi
94945 9085095 lksdjlkj
KEYWORD1 skljfi slakjfoi ' opiport sdfl
KEYWORD2 ksjflsk jfasope
jkdfsk393 89374982 23

Please help me!
Thanks
  #2 (permalink)  
Old 11-25-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
something to start with

Code:
awk '/KEYWORD1/ {getline; if($1 == "KEYWORD2") print "Success at line no ", NR}' filename
  #3 (permalink)  
Old 11-25-2006
fongthai fongthai is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 54
It so great!
Thank you, ranj@chn!
  #4 (permalink)  
Old 11-25-2006
ask.jackal ask.jackal is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 24
awk '/KEYWORD2/ { if ( prev !~ /KEYWORD1/ ) {print "Error at " NR}} {prev = $0 }' <sample.txt

John Arackal
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 07: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