- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Script help...awk
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-20-2006 03:20 AM
тАО09-20-2006 03:20 AM
Thanks
IE:
linea
lineb
linec
lined
grep linec | awk print linec and lineb
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-20-2006 03:24 AM
тАО09-20-2006 03:24 AM
Solutiondo
grep "string" $line 1>/dev/null 2>/dev/null
if [ $? -eq 0 ]
then
echo ${lastline}
echo ${line}
fi
lastline=${line}
done
I know there is a bug if the string comes on the first line. I can not think of a solution for it. May be the perl masters will give you a good colution.
Regards,
Kaps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-20-2006 03:33 AM
тАО09-20-2006 03:33 AM
Re: Script help...awk
#!/usr/bin/sh
end=`grep -n linec file | awk -F':' '{print $1}'`
start=`expr $end - 1`
sed -n '$start,$endp' file
or better:
get gnu grep and do:
grep -B1 linec
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-20-2006 03:36 AM
тАО09-20-2006 03:36 AM
Re: Script help...awk
# cat file
linea
lineb
linec
lined
# awk '/linec/{print x; print};{x=$0}' file
lineb
linec
PCS
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-20-2006 03:42 AM
тАО09-20-2006 03:42 AM