|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | 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 and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
awk /OUTPUT/,/END/ filename|grep -v 'OUTPUT^JEND'
or awk /OUTPUT/,/END/ filename|grep -v 'OUTPUT END' |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
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
|
||||
|
||||
|
In awk: Code:
awk ' /OUTPUT/ {flag=1;next} /END/{flag=0} flag { print }' file |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
sed
Hi, I think this one is easy. Code:
sed -e '1,/OUTPUT/d' -e '/END/,$d' file |
| The Following User Says Thank You to summer_cherry For This Useful Post: | ||
vertigo23 (03-11-2011) | ||
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Print lines between two strings multiple occurencies (with sed, awk, or grep) | theclem35 | Shell Programming and Scripting | 8 | 07-25-2012 04:24 AM |
| Strings from one file which exactly match to the 1st column of other file and then print lines. | AshwaniSharma09 | Shell Programming and Scripting | 4 | 08-19-2010 08:16 PM |
| print lines between two strings but for the first occurence. solved | Sangal_ak04 | Shell Programming and Scripting | 0 | 04-26-2010 05:40 PM |
| Compare two strings, and print lines containing mismatches | kingpeejay | Shell Programming and Scripting | 1 | 07-06-2009 11:23 PM |
| Print all the lines between 2 specified strings | digitalrg | Shell Programming and Scripting | 7 | 04-17-2009 08:29 AM |
|
|