Results 1 to 4 of 4
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 ...
- 02-16-2008 #1Just Joined!
- Join Date
- Feb 2008
- Posts
- 5
AWK Help Needed
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
I put a <sp> to indicate a space in the way it looks in my file. The <sp> is not there.
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?
- 02-16-2008 #2Linux User
- Join Date
- Aug 2006
- Posts
- 458
Code:# awk '$3 !~/^[A-Z]$/{print $1,$2}' file Volume 0
- 02-16-2008 #3Just Joined!
- Join Date
- Feb 2008
- Posts
- 5
When I run that command I get the following output
Volume 0 Volume 1 Volume 2 Volume 3
In this case Volume 3 is not the one without a drive letter.
- 02-16-2008 #4Just Joined!
- Join Date
- Feb 2008
- Posts
- 5
I had one of the commands wrong. I get what I need but I think I need to tweek 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:


Reply With Quote