![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | 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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
awk /OUTPUT/,/END/ filename|grep -v 'OUTPUT^JEND'
or awk /OUTPUT/,/END/ filename|grep -v 'OUTPUT END' |
|
#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
|
|
#5
|
|||
|
|||
|
sed
Hi,
I think this one is easy. Code:
sed -e '1,/OUTPUT/d' -e '/END/,$d' file |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|