|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Formatting output
I have the output like below:
HTML Code:
DEV#: 9 DEVICE NAME: hdisk9 TYPE: 1750500 ALGORITHM: Load Balance
SERIAL: 68173531021
==========================================================================
Path# Adapter/Path Name State Mode Select Errors
0 fscsi0/path0 OPEN NORMAL 100920851 0
1* fscsi1/path1 OPEN NORMAL 7 0
DEV#: 10 DEVICE NAME: hdisk10 TYPE: 1750500 ALGORITHM: Load Balance
SERIAL: 68173531022
===========================================================================
Path# Adapter/Path Name State Mode Select Errors
0 fscsi0/path0 OPEN NORMAL 75036048 0
1* fscsi1/path1 OPEN NORMAL 63 0
DEV#: 11 DEVICE NAME: hdisk11 TYPE: 1750500 ALGORITHM: Load Balance
SERIAL: 68173531025
===========================================================================
Path# Adapter/Path Name State Mode Select Errors
0 fscsi0/path0 OPEN NORMAL 318733022 0
1* fscsi1/path1 OPEN NORMAL 7 0
DEV#: 12 DEVICE NAME: hdisk12 TYPE: 1750500 ALGORITHM: Load Balance
SERIAL: 68173531026
===========================================================================
Path# Adapter/Path Name State Mode Select Errors
0 fscsi0/path0 OPEN NORMAL 85608664 0
1* fscsi1/path1 OPEN NORMAL 7 0
DEV#: 13 DEVICE NAME: hdisk13 TYPE: 1750500 ALGORITHM: Load Balance
SERIAL: 68173531027
===========================================================================
Path# Adapter/Path Name State Mode Select Errors
0 fscsi0/path0 OPEN NORMAL 202312366 0
1* fscsi1/path1 OPEN NORMAL 21 0
DEV#: 14 DEVICE NAME: hdisk14 TYPE: 1750500 ALGORITHM: Load Balance
SERIAL: 68173531028
===========================================================================
Path# Adapter/Path Name State Mode Select Errors
0 fscsi0/path0 OPEN NORMAL 238355812 0
1* fscsi1/path1 OPEN NORMAL 7 0
......
HTML Code:
DEVICE NAME SERIAL hdisk9 1021 hdisk10 1022 .... Please advise. |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Try: Code:
awk '/DEV/{
getline p
split(p,F)
if(NR==2) print $3 FS $4,F[1]
print $5, substr(F[2],length(F[2])-3,4)
}
' OFS='\t' infile |
| The Following User Says Thank You to Scrutinizer For This Useful Post: | ||
Daniel Gate (02-03-2013) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
If your file structure is always as displayed above, i.e. the serial in in the next line after device name, try Code:
awk 'BEGIN{print "DEVICE NAME\tSERIAL"} /DEVICE NAME/ {printf "%s\t", $5; getline; print substr($2, length($2)-3)}' file
DEVICE NAME SERIAL
hdisk9 1021
hdisk10 1022
hdisk11 1025
hdisk12 1026
hdisk13 1027
hdisk14 1028 |
| The Following User Says Thank You to RudiC For This Useful Post: | ||
Daniel Gate (02-03-2013) | ||
|
#4
|
||||
|
||||
|
Not much difference from solutions posted above: Code:
awk -F":" ' BEGIN {
printf "DEVICE NAME\tSERIAL\n";
} /DEVICE NAME:/ {
d = $3;
sub(" ",x,d);
sub(/[ \t].*/,x,d);
getline;
s = substr($2,length($2)-3);
printf "%s\t\t%s\n", d, s;
} ' filename
DEVICE NAME SERIAL
hdisk9 1021
hdisk10 1022
hdisk11 1025
hdisk12 1026
hdisk13 1027
hdisk14 1028 |
| The Following User Says Thank You to Yoda For This Useful Post: | ||
Daniel Gate (02-03-2013) | ||
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Thank you! It works perfect!
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Formatting the output | arijitsaha | Shell Programming and Scripting | 2 | 06-12-2012 07:57 AM |
| Formatting df output | newbie_01 | UNIX for Dummies Questions & Answers | 4 | 08-01-2011 05:23 AM |
| Output formatting . | pinga123 | Shell Programming and Scripting | 5 | 03-25-2011 08:09 AM |
| more help with formatting ls output... | patrick99e99 | Shell Programming and Scripting | 1 | 10-27-2009 01:29 AM |
| Formatting the output | Cameron | Shell Programming and Scripting | 7 | 02-15-2002 09:30 AM |
|
|