- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Can awk help in the below situation?
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
тАО07-21-2002 07:01 PM
тАО07-21-2002 07:01 PM
3/1
3/2
3/3
up
down
up
2 days
5 days
10 day
May I know how I can produce the above results to be shown as below? Please advise, thank you.
port status time
3/1 up 2 days
3/2 down 5 days
3/2 up 10 days
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2002 07:31 PM
тАО07-21-2002 07:31 PM
Re: Can awk help in the below situation?
Here's one lazy and quick solution, assuming that you don't mind the x-axis and y-axis being swapped:
# echo port `cat datafile | head -3` ; echo status `cat datafile | head -6 | tail -3` ; echo time `cat datafile | head -9 | tail -3`
port 3/1 3/2 3/3
status up down up
time 2 days 5 days 10 day
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2002 07:58 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2002 08:01 PM
тАО07-21-2002 08:01 PM
Re: Can awk help in the below situation?
I think the solution will be suitable if there is only one single set of data and also provided I know the number of ports.
However, in the actual scenarion, the script will capture about 100 over sets of similar data as above, and each box has random number of port. In above example, it only shows 3 rows (port 3/1,3/2,3/3), but in real case, I may have one box having 48 ports and another box having 96 ports.
I hope this can help to clarify the situation.
Box 1
======
3/1
3/2
3/3
up
up
up
3 days
4 days
4 days
Box 2
=====
1/1
1/2
1/3
1/4
1/5
1/6
..........
..........
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2002 08:15 PM
тАО07-21-2002 08:15 PM
Re: Can awk help in the below situation?
Can you try the following script to generate the results ??
=== BEGIN ===
#!/bin/ksh
i=1
num=`wc -l yourfile.txt | awk '{print $1}`
cat yourfile.txt | while read a
do
name[$i]=$a
let i=$i+1
done
j=1
while [ $j -le `expr $num / 3` ]
do
echo ${name[$j]} ${name[$j+3]} ${name[$j+6]}
let j=$j+1
done
=== END ===
If you have to group 4 rows, just replace 3,6 with 4,8 and add one more variable ${name[$j+12]}.
Regards,
Patrick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2002 08:29 PM
тАО07-21-2002 08:29 PM
Re: Can awk help in the below situation?
Sorry forget that "2 days" is the whole line.
Just change the script to the following,
i=1
num=`wc -l yourfile.txt | awk '{print $1}`
cat yourfile.txt | while read LINE
do
name[$i]=$LINE
let i=$i+1
done
j=1
while [ $j -le `expr $num / 4` ]
do
echo ${name[$j]} ${name[$j+3]} ${name[$j+6]} ${name[$j+9]}
let j=$j+1
done
And '4' is the value to group how many data in a row of the result.
If you have 4 sets of data, just replace 3,6,9 with 4,8,12
Regards,
Patrick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2002 09:01 PM
тАО07-21-2002 09:01 PM
Re: Can awk help in the below situation?
>> Below is the output statistics from a snmpwalk script file.
I believe it will be easier for you to work directly on the snmpwalk script itself to output appropriate than to work around the existing output.
The other thing is perhaps it might be easier to use snmpget and format each snmpget record individually than using snmpwalk and format the entire table.
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2002 09:44 PM
тАО07-21-2002 09:44 PM
Re: Can awk help in the below situation?
# perl -ne 'm:^\d+/:&&push@x,$_ or/^\d+ day/&&push@y,$_ or push@z,$_;}END{chomp@x;chomp@z;$,="\t";print$_,shift(@z),shift@y for@x' xx
3/1 up 2 days
3/2 down 5 days
3/3 up 10 day
# cat xx
3/1
3/2
3/3
up
down
up
2 days
5 days
10 day
#
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-23-2002 01:49 AM
тАО07-23-2002 01:49 AM
Re: Can awk help in the below situation?
Here is a small awk script that should do what you want:
#!/usr/bin/sh
awk '
BEGIN { print "Port Status Time" }
{ buf[NR] = $0 }
END { size = NR
# Work out how many ports we have
no_ports = 0
for ( i = 1 ; i <= size ; i++ )
{
if ( buf[i] == "up" || buf[i] == "down" )
{
break
}
++no_ports
}
for ( i = 1 ; i <= no_ports ; i++ )
{
print buf[i], buf[i+no_ports], buf[i+(2*no_ports)]
}
}' /tmp/snmpwalk
It will work N number of ports as long as the format of the smnpwalk file remains as in your posting.
Cheers,
Joseph
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-24-2002 12:44 AM
тАО07-24-2002 12:44 AM
Re: Can awk help in the below situation?
Thanks for all the contributions.
I finally managed to get the output by modifying the script file and incorporating with the commands recommended. Using the paste as suggested by kumar can produce the required results.
Cheers,
Cynthia