1748194 Members
4073 Online
108759 Solutions
New Discussion юеВ

awk printing

 
SOLVED
Go to solution
lawrenzo_1
Super Advisor

awk printing

Hello,

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
hello
11 REPLIES 11
Victor Fridyev
Honored Contributor

Re: awk printing

Hi,

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
Entities are not to be multiplied beyond necessity - RTFM
Tim Nelson
Honored Contributor

Re: awk printing

Here is the summary of the script I use to gather disk usage reporting.

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,
Sandman!
Honored Contributor

Re: awk printing

Could you provide a sample of the two input files i.e. "paceds.lsfbvol.out" and "paceds.lshostvol.out". grep(1) might be able to work just as well depending on the contents of the two files.

~thanks
James R. Ferguson
Acclaimed Contributor

Re: awk printing

Hi Chris:

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...
blah2blah
Frequent Advisor

Re: awk printing

cat lshost |
awk -v f2="lsfbvol" '
BEGIN {
while ( getline < f2 > 0 ) a[$2]=1;
}
{
if ( a[$2] ) print "found";
else print "not found";
}
Dennis Handly
Acclaimed Contributor

Re: awk printing

You can of course do this several ways. If your files have the same format, you can use sort and comm, something like Victor's.

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?
lawrenzo_1
Super Advisor

Re: awk printing

ok here is the sample form each file:

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
hello
Dennis Handly
Acclaimed Contributor

Re: awk printing

>here is the sample form each file:
>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.)
lawrenzo_1
Super Advisor

Re: awk printing

Thanks Dennis,

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.
hello