- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: awk script help
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
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
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-10-2013 12:03 PM
08-10-2013 12:03 PM
I have this following script which lists out packages on a filesystem (but NOT the latest package) on a filesystem.
I want to avoid listing out the latest 3 packages instead of one.
ls -l | awk '
BEGIN { prev = ""; app = "" }
{
n = split($9, apps, "-")
if (n == 0) next
if (n < 2) {
print "problem getting appname for", $9
next
}
appname = apps[1]
if (appname == app) {
print prev # older
prev = $9 # save
next
}
app = appname
prev = $9
} '
Thanks,
Allan.
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2013 04:28 PM - edited 08-13-2013 12:19 AM
08-10-2013 04:28 PM - edited 08-13-2013 12:19 AM
Re: awk script help
>I want to avoid listing out the latest 3 packages instead of one.
I suppose you could have multiple "prev" buffers and shuffle them down.
Or create a circular buffer.
BEGIN { app = "" }
...
if (appname == app) {
if (prev[nn] != "")
print prev[nn] # older
prev[nn++] = $9 # save
if (nn >=3) nn = 0
next
}
app = appname
# flush prev array
for (nn in prev) delete prev[nn]
nn = 0
prev[nn++] = $9 # save
} '
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2013 09:15 AM
08-11-2013 09:15 AM
Re: awk script help
Thanks Dennis, for the reply.
I tried the circular buffer but that shows the latest packge.
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2013 12:47 PM
08-12-2013 12:47 PM
Re: awk script help
>I tried the circular buffer but that shows the latest package.
Hmm, I'll have to check it out later to day.
Have you tried only 1, 2, 3, 4, 5, 6 packages and see what happens?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2013 12:21 AM