- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- grep using awk then head and tail
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
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
тАО08-22-2002 11:58 AM
тАО08-22-2002 11:58 AM
My feeble attempts need help!
I'mwas attempting to use;
cat -n $file | grep PARM | awk '{print $1}' | head -n ${1} $file .
the cat -n $file | grep PARM | awk '{print $1}' works fine, but how do I pass that to head -n ?
Thank you ~jdk
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2002 12:01 PM
тАО08-22-2002 12:01 PM
Solutionexample-
head -n $(echo 4) filename
In your example, replace all those commands for the "echo 4".
Their might be an easier way to do what you are trying to do. Can you rephrase your question in terms of what results you are looking for.
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2002 12:01 PM
тАО08-22-2002 12:01 PM
Re: grep using awk then head and tail
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2002 12:04 PM
тАО08-22-2002 12:04 PM
Re: grep using awk then head and tail
Use
cat $file | grep PARM | awk '{print $1}' | head -10
HTH
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2002 12:07 PM
тАО08-22-2002 12:07 PM
Re: grep using awk then head and tail
Sample using an IOSCAN I did to a file:
cat -n $file | grep C895 | awk '{print $1}' | xargs -i head -n {} $file
Class I H/W Path Driver S/W State H/W Type Description
============================================================================
root 0 root CLAIMED BUS_NEXUS
ioa 0 0 sba CLAIMED BUS_NEXUS System Bus Adapter (803)
ba 0 0/0 lba CLAIMED BUS_NEXUS Local PCI Bus Adapter (782)
lan 0 0/0/0/0 btlan CLAIMED INTERFACE HP PCI 10/100Base-TX Core
/dev/diag/lan0 /dev/ether0 /dev/lan0
ext_bus 0 0/0/1/0 c720 CLAIMED INTERFACE SCSI C895 Fast Wide Single-Ended
#
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2002 12:33 PM
тАО08-22-2002 12:33 PM
Re: grep using awk then head and tail
I need to go through a file, find all occurences of $name1, then echo out that line and the line prior to it.
I also need to find $name2 and echo out that line and several after it.
ie If I already know the line #, I can use "head -n line# | tail -1 or head +4.
Does that make more sense?
Thanks again, ~jdk
ps ALL of you get and deserve 10 points eitherway
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2002 12:34 PM
тАО08-22-2002 12:34 PM
Re: grep using awk then head and tail
cat -n $file | grep C895 | awk '{printf "head -n %d %s \| tail -n %s\n",$1+2,"XZ
X",$1-1;}' | sed "s,XZX,${file},g" | xargs -i sh {}
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2002 12:41 PM
тАО08-22-2002 12:41 PM
Re: grep using awk then head and tail
perl -n -e '$s2=$s1;$s1=$_;/mno/ && do {print "$s2$s1"}' $file
Hope this helps...
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2002 12:47 PM
тАО08-22-2002 12:47 PM
Re: grep using awk then head and tail
cat -n cmaudit | grep BEGIN | awk '{print $1}' | head -n '{print $1}' cmaudit | tail -5 . Can you point out the error of my ways?
Harry, I'm using a test machine so I tried your mind blower, modified of course....it returned empty. I'm not quite sure I understand all it does, or if I could understand it anyway!
I will give the perl scripting a try, and get back to you Rod.
Thanks again! ~jdk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2002 12:56 PM
тАО08-22-2002 12:56 PM
Re: grep using awk then head and tail
sed -n -e `grep -n $name1 $file | awk -F: '{print $1 - 1 "," $1 "p"}'` $file
sed -n -e `grep -n $name2 $file | awk -F: '{print $1 "," $1 + 7 "p"}'` $file
The first finds $name1 and prints line prior and current line.
The second finds $names and prints line plus 7 additional lines.
Hope this helps.
-- Rod Hills