The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
assign a command line argument and a unix command to awk variables sweta_doshi Shell Programming and Scripting 0 08-08-2008 06:54 AM
Help Required: Command to find IP address and command executed of a user loggedout Security 2 08-06-2008 08:12 PM
how to? launch command with string of command line options TinCanFury Shell Programming and Scripting 5 04-28-2008 06:06 PM
inconsistent ls command display at the command prompt & running as a cron job rajranibl SuSE 5 07-30-2007 08:26 AM
How to use more than one MPE command STREAM with Unix command in a single shell? bosskr HP-UX 1 10-16-2006 04:16 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-30-2008
mansa mansa is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 33
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.
  #2 (permalink)  
Old 10-30-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,277
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.
  #3 (permalink)  
Old 10-30-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,531
another way
Code:
# awk -F":| " '/^(a|b|g|h)/&&$5=="unused"{print $1}' file
  #4 (permalink)  
Old 10-30-2008
mansa mansa is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 33
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.
  #5 (permalink)  
Old 10-30-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,531
then use zaxxon's method.
  #6 (permalink)  
Old 10-30-2008
mansa mansa is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 33
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
  #7 (permalink)  
Old 10-30-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,531
execute the awk commands on the command line and see what you get. don't assign to any variables yet !
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0