AWK Problem Need Help!

I have a problem that I have not be able to get solved. First of all the script I am writing is for a Windows server. I am trying to write a script that will connect to a ISCSI SAN and locate the last Snapshot for that server and mount it for a backup. In order to capture the screens I have been redirecting the output to a text file then using CYGWIN and GAWK to parse the file and extract the information I need to pass into another file which is named a bat file which is executed for the next step. I have everything working except the last critical step. When I connect to the snapshot the volume does not mount with a drive letter. When I run a diskpart I can see the disk number (without a letter). I then need to run a few diskpart commands to connect to the volume before I can assign a letter of my choice.

Now for the issue. The output of the file is a follows:

Volume 0<sp> Data NTFS Partition 400 GB Healthy
Volume 1 Z <sp><sp> DVD-ROM 0 GB Healthy
Volume 2 C <sp> NTFS Partition 21 GB Healthy System
Volume 3 D Data1 NTFS Partition 115 GB Healthy
(<sp> is there only to indicate there is a blank space)

What I need to do is extract the line that does not have a drive letter. I would like to use awk for this. The problem is that this line is not always the first line nor Volume 0. The only thing that is constant is that is will not have a drive letter. When I try a $3 for the third field it treats the word Data as the third field since its blank. I was hopeing something like

$3 // { print $1, $2 }

Can any one help?

awk '!/^Volume [0-9] [A-Z]/ { print($1,$2) }' input_file

I ran that and what I get is the following on one line:

Volume 0 Volume 1 Volume 2 Volume 3.

What I need dispayed is only the Volume that does not have a drive letter.

As far as the awk above is concerned Volume 0 Data is the same as Volume 0 D.
Does the word "Data " always appear for any volume you need? I see Data1.

It can depending on what volume is being mounted. The only thing that is unique is the one that needs to be mounted does not have a drive letter.

My bad I had a { rather than a [ in the A-Z search. It is working now...

Thanks! I realy appreciate the help.

I tweeked some things and I think I got it working but I need help with the output

This is what I got.

$3 !~/^[A-Z]$/ { print "Select " $1, $2 ; print "Assign " ENVIRON["BCKDRIVE"] }
(all on one line)
This prints the following:

Select Volume 0 Assign K:

What I need is for the Assign K: to be on a new line

Select Volume 0
Assign K:

... { print "Select " $1, $2 "\nAssign " ENVIRON["BCKDRIVE"] } ...
awk '!$3 { printf "Select %s %s\nAssign %s\n", $1, $2, ENVIRON["BCKDRIVE"] }' FS='[ ]' input

This is what I have

$3 !~/[1]$/ { print "Select " $1, $2 "\nAssign " ENVIRON["BCKDRIVE"] }
Still displays everything in one line.

I


  1. A-Z ↩︎

When I put the following into my code
$3 !~/[1]$/ { printf "Select %s %s\nAssign %s\n", $1, $2, ENVIRON["BCKDRIVE"] }' FS='' input
(entered as one line)

I get no output.


  1. A-Z ↩︎

I didn't post the code you're showing ...


  1. A-Z ↩︎

Consider this:

% cat file
Volume 0  Data NTFS Partition 400 GB Healthy
Volume 1 Z    DVD-ROM 0 GB Healthy
Volume 2 C   NTFS Partition 21 GB Healthy System
Volume 3 D Data1 NTFS Partition 115 GB Healthy
% export BCKDRIVE="K:"
% awk '!$3 { printf "Select %s %s\nAssign %s\n",
$1, $2, ENVIRON["BCKDRIVE"] }' FS='[ ]' file
Select Volume 0
Assign K:

Or your input file is different ...

I have the output I need I just need to get it one two lines. I need:

Select Volume x
Assign K:

On two seperate lines. Right now both are on one line. I thought a semicolon was suppose to put the second print command on a new line. Then I tried playing around with a /n to force a new line but could not get it to work.

I don't have MS Windows right now, another shot in the dark:

awk '!$3 { printf "Select %s %s\r\nAssign %s\r\n", $1, $2, ENVIRON["BCKDRIVE"] }' FS='[ ]' input