how to get text with sed?
i want to grab the the text between tok98 and 5678 and dump that out to a file.
if the tok98 and the 5678 was on the same line i can use this
sed -n 's/.*(tok98)(.*)(5678).*/2/p' testfile.txt > text.dmp
but when the tokens are vertically spaced its not working, how can i rewrite this sed to work here
$ cat testfile.txt
do with > 9
tok98
fdf df s df sd f sd v
dvsdv dvf sd vs vs dv sdfsd 2323 2323 232 {}
sfdf sd f s df s df sf
5678
no way = true + 50$
You can use /START/,/STOP/ pattern ranges in sed
sed -n '/tok98/,/5678/p' file
/START/ and /STOP/ can be REs too
sed -n '/^tok98/,/^5678/p' file
would print between the lines starting tok98 and 5678 and would not start or stop unless the lines begin with those strings.
If you want to exclude the /START/ and /STOP/ then this should work
sed -n '/^tok98/,/^5678/ {/^tok98/b;/^5678/b;p}' file
Check more discussion of this question.
Related posts:
Leave a comment
Recent Posts
Tags
active-directory
amazon-ec2
apache
apache2
backup
bash
centos
cisco
command-line
debian
dns
email
exchange
firewall
iis
iis7
iptables
linux
macosx
monitoring
mysql
networking
nginx
performance
permissions
php
postfix
raid
security
sql-server
sql-server-2005
sql-server-2008
ssh
ssl
ubuntu
unix
virtualization
vpn
webserver
windows
windows-7
windows-server-2003
windows-server-2008
windows-server-2008-r2
windows-xp





