- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- awk printing
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
тАО10-08-2007 03:16 AM
тАО10-08-2007 03:16 AM
I am attempting to use awk to search the lunid that exists in one file but not the other so:
for lunid in `awk 'FS="," {print $2}' paceds.lsfbvol.out`
do
awk -v lun=$lunid '/'"$lunid"'/ {if ( NF > 0) print lun,$0 >> "myoutfile"} {if ( NF == 1 ) print lun,",," >> "myoutfile"}'
paceds.lshostvol.out
done
I am sure there is no need to run this through the shell for loop and can be done in awk.
the first file paceds.lsfbvol.out details all luns in our Storage .....
paceds.lshostvol.out file is missing 2 luns so I want to be able to seach the second file for all luns ($2) and if not there print the line from paceds.lsfbvol.out and have ",," if the line exists just print $0 from paceds.lsfbvol.out into myoutfile.
a sample of the line:
fl_olas_0_2000,2000,Online,Normal,Normal,2107-900,FB 512,P0,36.0,-,75497472
thanks guys ....
Chris
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2007 03:27 AM
тАО10-08-2007 03:27 AM
Re: awk printing
IMHO, you don't need awk, you can use something like that:
cat paceds.lsfbvol.out paceds.lshostvol.out | sort | uniq -u
This will print you exactly the luns which are absent in the full list.
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2007 03:33 AM
тАО10-08-2007 03:33 AM
Re: awk printing
1) get list of all disk device files
2) run this list through while read loop and use it to determine disk size, vg, lv and free extents using diskinfo, vgdisplay, pvdisplay commands.
3) if none of the above are found on the disks then it is available for user.
4) output in comma separated or formatted file for reporting.
Example is below.
1/0/10/1/0.0.0,/dev/dsk/c8t0d0,EXT,P,/dev/vgdata1/adm_fsdmo84,/u01/oracle/admin/fsdmo84,143GB
, , ,P,/dev/vgdata1/adm_hrdmo83,/u01/oracle/admin/hrdmo83,
, , ,P,/dev/vgdata1/adm_qfonyx,/u01/oracle/admin/qfonyx,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2007 03:34 AM
тАО10-08-2007 03:34 AM
Re: awk printing
~thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2007 03:55 AM
тАО10-08-2007 03:55 AM
Re: awk printing
You could use a 'getline' to read your first file in a 'BEGIN' block into an array which you then process against the second file.
...
BEGIN{while (getline LINE < "paceds.lsfbvol.out" > 0) {a[++$i]=LINE}}
...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2007 04:17 AM
тАО10-08-2007 04:17 AM
Re: awk printing
awk -v f2="lsfbvol" '
BEGIN {
while ( getline < f2 > 0 ) a[$2]=1;
}
{
if ( a[$2] ) print "found";
else print "not found";
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2007 08:11 PM
тАО10-08-2007 08:11 PM
Re: awk printing
You can create two tmp files, each prefixed by the file and the key, and then sort by key, then file and then use awk to read "pairs" of lines.
Note: your sample script above goes to the trouble of using awk -v then you use a quoting nightmare to get $lunid inside //. If you want a RE that's not a constant you can use:
awk -v lun=$lunid '$0 ~ lun { if ...
And you can also move that "if" into your pattern:
awk -v lun=$lunid '$0 ~ lun && NF > 1 { ...
Note: I changed that NF > 0 to NF > 1 in the last line. But you might as well remove it since if you have a match, there is one field. And after you print it, you might as well use "exit".
>if not there print the line from paceds.lsfbvol.out and have ",," if the line exists just print $0 from paceds.lsfbvol.out into myoutfile.
Your current script can only print the values out from paceds.lshostvol.out, the file you are currently processing.
So as Sandman asks, what is the format of each file?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2007 08:50 PM
тАО10-08-2007 08:50 PM
Re: awk printing
more paceds.lsfbvol.out
olas_0_1000,1000,Online,Normal,Normal,2107-900,FB 512,P0,36.0,-,75497472
olas_0_1001,1001,Online,Normal,Normal,2107-900,FB 512,P0,36.0,-,75497472
olas_0_1002,1002,Online,Normal,Normal,2107-900,FB 512,P0,36.0,-,75497472
olas_0_1003,1003,Online,Normal,Normal,2107-900,FB 512,P0,36.0,-,75497472
olas_0_1004,1004,Online,Normal,Normal,2107-900,FB 512,P0,36.0,-,75497472
olas_0_1005,1005,Online,Normal,Normal,2107-900,FB 512,P0,36.0,-,75497472
$2 being the lun id
and from the file searched where the lun id does not exist:
# more paceds.lshostvol.out
hdisk4,IBM.2107-75FDFW1/3000,vpath0
hdisk5,IBM.2107-75FDFW1/3001,vpath1
hdisk6,IBM.2107-75FDFW1/3002,vpath2
hdisk7,IBM.2107-75FDFW1/3003,vpath3
hdisk8,IBM.2107-75FDFW1/3004,vpath4
hdisk9,IBM.2107-75FDFW1/3005,vpath5
hdisk10,IBM.2107-75FDFW1/3006,vpath6
hdisk11,IBM.2107-75FDFW1/3007,vpath7
hdisk12,IBM.2107-75FDFW1/3008,vpath8
hdisk13,IBM.2107-75FDFW1/3009,vpath9
hdisk14,IBM.2107-75FDFW1/3100,vpath10
hdisk15,IBM.2107-75FDFW1/3101,vpath11
hdisk16,IBM.2107-75FDFW1/3102,vpath12
hdisk17,IBM.2107-75FDFW1/3103,vpath13
hdisk18,IBM.2107-75FDFW1/3104,vpath14
hdisk19,IBM.2107-75FDFW1/3105,vpath15
hdisk20,IBM.2107-75FDFW1/3106,vpath16
hdisk21,IBM.2107-75FDFW1/3107,vpath17
hdisk22,IBM.2107-75FDFW1/3108,vpath18
hdisk95,hdisk105,IBM.2107-75FDFW1/1102,vpath47
hdisk96,hdisk106,IBM.2107-75FDFW1/1103,vpath48
hdisk100,hdisk141,IBM.2107-75FDFW1/1104,vpath49
I am still messing about with the suggestions above so will keep you updated.
thanks all.
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2007 09:18 PM
тАО10-08-2007 09:18 PM
Re: awk printing
>paceds.lsfbvol.out:==========================================
olas_0_1000,1000,Online,Normal,Normal,2107-900,FB 512,P0,36.0,-,75497472
>$2 being the lun id
>from the file searched where the lun id does not exist:
>paceds.lshostvol.out
hdisk4,IBM.2107-75FDFW1/3000,vpath0
I don't see any matches. Can you provide at least one in the second file? Since there aren't any, I don't know what "field" I should be looking at? After the "/"?
And you seem to have more comma separated fields on the last three.
And if a LUN in the first is in the second, you want to print out that line in the first or second? (You seemed to have said first in your initial question.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2007 10:02 PM
тАО10-08-2007 10:02 PM
Re: awk printing
I will close this post down now as I will carry on with my notes and repost the question when I have more of an idea - I have seen the "/" in the latter fields so need to work out how to negate that.
Thanks all for your help
Chris.