The UNIX and Linux Forums

The UNIX and Linux Forums (http://www.unix.com/index.php)
-   Shell Programming and Scripting (http://www.unix.com/shell-programming-and-scripting/)
-   -   AWK command (http://www.unix.com/shell-programming-and-scripting/87301-awk-command.html)

mansa 10-30-2008 02:27 AM

AWK command
 
Hi,

Please help me in doing this..


$ disklabel dsk1
# /dev/rdisk/dsk1c:
type: SCSI
disk: BD018635C4
label:
flags: dynamic_geometry
bytes/sector: 512
sectors/track: 254
tracks/cylinder: 20
sectors/cylinder: 5080
cylinders: 7001
sectors/unit: 35565080
rpm: 10025
interleave: 1
trackskew: 84
cylinderskew: 74
headswitch: 0 # milliseconds
track-to-track seek: 0 # milliseconds
drivedata: 0
8 partitions:
# size offset fstype fsize bsize cpg # ~Cyl values
a: 131072 0 unused 0 0 # 0 - 25*
b: 262144 131072 unused 0 0 # 25*- 77*
c: 35565080 0 unused 0 0 # 0 - 7000
d: 0 0 unused 0 0 # 0 - 0
e: 0 0 unused 0 0 # 0 - 0
f: 0 0 unused 0 0 # 0 - 0
g: 17585932 393216 unused 0 0 # 77*- 3539*
h: 17585932 17979148 unused 0 0 # 3539*- 7000

Above is the "disklabel" (command) output .

From above output first it must take 4 partitions(a: , b: , g: . h: ) .

And it must check fstype column =unused for all above 4 partitions.And among those 4 partitions finally i need the partitions which has fstype=unused.


Please let me know how to get the output by using awk or by any other commands..



Thanks,
mansa.

zaxxon 10-30-2008 03:42 AM

Code:

awk '/^a|^b|^g|^h/ && $4 == "unused" {sub(/:/,"",$1); print $1}' infile
Since all 4 wanted partitions have "unused", you will get all 4 of them.

ghostdog74 10-30-2008 04:33 AM

another way
Code:

# awk -F":| " '/^(a|b|g|h)/&&$5=="unused"{print $1}' file

mansa 10-30-2008 05:12 AM

Hi,

I tried as below way..

$ disklabel dsk2 > file

$ t=`awk -F":| " '/^(a|b|g|h)/&&$5=="unused"{print $1}' file`
$ echo $t

$

I didnt get any output...

Please let me know how can i get value in "t" variable..

Thanks,
mansa.

ghostdog74 10-30-2008 05:27 AM

then use zaxxon's method.

mansa 10-30-2008 06:33 AM

Hi zaxxon,

I tried as per your comments..Could you please look at it...

$ disklabel dsk2 > infile

t=`awk '/^a|^b|^g|^h/ && $4 == "unused" {sub(/:/,"",$1); print $1}' infile`
$ echo $t


$

It didnt display any output...

Could you please let me know how to get value in $t.

Thanks in Advance,
Mansa

ghostdog74 10-30-2008 07:03 AM

execute the awk commands on the command line and see what you get. don't assign to any variables yet !


All times are GMT -4. The time now is 08:46 AM.

Linux and Unix Supported by: vBulletin
Search Engine Optimisation provided by DragonByte SEO v1.1.4 (Pro) - vBulletin Mods & Addons Copyright © 2014 DragonByte Technologies Ltd.
The UNIX and Linux Forums Content Copyright ©1993-2013. All Rights Reserved.
Forum Operations by The UNIX and Linux Forums