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
Find lines with space between strings Galt Shell Programming and Scripting 5 05-07-2008 02:06 PM
Extracting lines between 2 strings only if the pattern patches simran Shell Programming and Scripting 5 04-23-2008 04:58 PM
replace 2 identical strings on different lines prkfriryce Shell Programming and Scripting 3 06-15-2007 11:18 AM
Extracting the lines between 2 strings of a file babloo Shell Programming and Scripting 2 02-14-2007 11:27 AM
many strings against 5million lines r0sc0 Shell Programming and Scripting 2 01-19-2006 09:04 PM

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

Join Date: Jan 2008
Location: Bangalore,India
Posts: 144
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
  #2 (permalink)  
Old 01-08-2008
ranjithpr ranjithpr is offline
Registered User
  
 

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

or

awk /OUTPUT/,/END/ filename|grep -v 'OUTPUT
END'
  #3 (permalink)  
Old 01-08-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,512
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"
  #4 (permalink)  
Old 01-08-2008
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
  
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 393
In awk:
Code:
awk ' /OUTPUT/ {flag=1;next} /END/{flag=0} flag { print }' file
  #5 (permalink)  
Old 01-11-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,079
sed

Hi,

I think this one is easy.

Code:
sed -e '1,/OUTPUT/d' -e '/END/,$d' file
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 03:09 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