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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Find lines with space between strings Galt Shell Programming and Scripting 5 05-07-2008 11:06 AM
Extracting lines between 2 strings only if the pattern patches simran Shell Programming and Scripting 5 04-23-2008 01:58 PM
replace 2 identical strings on different lines prkfriryce Shell Programming and Scripting 3 06-15-2007 08:18 AM
Extracting the lines between 2 strings of a file babloo Shell Programming and Scripting 2 02-14-2007 08:27 AM
many strings against 5million lines r0sc0 Shell Programming and Scripting 2 01-19-2006 06:04 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-07-2008
Registered User
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 138
How to print only lines in between two strings using awk

Hi,

I want to print only lines in between two strings and not the strings using awk.

Eg:
OUTPUT
top 2
bottom 1
left 0
right 0
page 66
END
I want to print into a new file only
top 2
bottom 1
left 0
right 0
page 66

Thanks in Advance
JS
Reply With Quote
Forum Sponsor
  #2  
Old 01-08-2008
Registered User
 

Join Date: Nov 2007
Posts: 85
awk /OUTPUT/,/END/ filename|grep -v 'OUTPUT^JEND'

or

awk /OUTPUT/,/END/ filename|grep -v 'OUTPUT
END'
Reply With Quote
  #3  
Old 01-08-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
there's a standard algo for doing this. turning on/off a flag
Code:
f=0
while read line
do
 case $line in 
  OUTPUT*) f=1; continue ;;
  END* ) f=0
 esac
 if [ "$f" -eq 1 ]; then
    echo $line 
 fi
done < "file"
Reply With Quote
  #4  
Old 01-08-2008
Klashxx's Avatar
HP-UX/Linux/Oracle
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 383
In awk:
Code:
awk ' /OUTPUT/ {flag=1;next} /END/{flag=0} flag { print }' file
Reply With Quote
  #5  
Old 01-11-2008
Registered User
 

Join Date: Jun 2007
Location: Beijing China
Posts: 495
sed

Hi,

I think this one is easy.

Code:
sed -e '1,/OUTPUT/d' -e '/END/,$d' file
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:15 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0