Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

relation mapping question
I am trying to map a relation from the following line format

hostA:/vol/vol9/dir	hostB:/vol/vol9/hostA_vol9_dir

The relation I want is

hostA:vol9 hostB:vol9	in that format, in a file.

(for those who are familiar with NetApp you will recognize this as a
snapvault configuration)

My total experience with awk can be sum'd up '{print $whatever.....}'
but the book is en route.

My guess is I can use multi BEGIN's and END's to define the FS for
each side of the mapping.  Something akin to

awk 'BEGIN {print $1;FS="/"; print $1$3} END BEGIN {print $2; FS="/";
print $1$3}'

I'm sure that the syntax is wrong but I hope I'm getting the idea
across.  My Unix in a Nutshell is just not much help.

Thanks.

~F

Report this thread to moderator Post Follow-up to this message
Old Post
Faeandar
10-08-04 01:55 AM


Re: relation mapping question
In article <8bibm0ldebd31069ll2vs6fckjob7alm03@4ax.com>,
Faeandar  <mr_castalot@yahoo.com> wrote:
>I am trying to map a relation from the following line format
>
>hostA:/vol/vol9/dir	hostB:/vol/vol9/hostA_vol9_dir
>
>The relation I want is
>
>hostA:vol9 hostB:vol9	in that format, in a file.

{
ORS=" "
for (i=1; i<=NF; i++) {
if (i==NF) ORS="\n"
split($i,T,/[:\/])
print T[1]":"T[3]
}
}


Report this thread to moderator Post Follow-up to this message
Old Post
Kenny McCormack
10-08-04 01:55 AM


Re: relation mapping question
On Thu, 07 Oct 2004 23:24:49 GMT, gazelle@yin.interaccess.com (Kenny
McCormack) wrote:

>In article <8bibm0ldebd31069ll2vs6fckjob7alm03@4ax.com>,
>Faeandar  <mr_castalot@yahoo.com> wrote: 
>
>{
>ORS=" "
>for (i=1; i<=NF; i++) {
>    if (i==NF) ORS="\n"
>    split($i,T,/[:\/])
>    print T[1]":"T[3]
>    }
>}

Jeezus, I don't even know what ORS is!  :)

Ok, for a follow-up, I realized I can change the spaces between the
sections into a "/" with sed, but forget the syntax to turn multiple
spaces into a single "/".  I know it's possible because I did it about
4 years ago for some NetBackup stuff.  Anyone remember that little
piece of trivia?

Btw Kenny, thanks.  I'll be testing this momentarily.

~F

Report this thread to moderator Post Follow-up to this message
Old Post
Faeandar
10-08-04 01:55 AM


Re: relation mapping question
On Thu, 07 Oct 2004 23:06:17 GMT, Faeandar <mr_castalot@yahoo.com>
wrote:

>I am trying to map a relation from the following line format
>
>hostA:/vol/vol9/dir	hostB:/vol/vol9/hostA_vol9_dir
>
>The relation I want is
>
>hostA:vol9 hostB:vol9	in that format, in a file.
>
>(for those who are familiar with NetApp you will recognize this as a
>snapvault configuration)
>
>My total experience with awk can be sum'd up '{print $whatever.....}'
>but the book is en route.
>
>My guess is I can use multi BEGIN's and END's to define the FS for
>each side of the mapping.  Something akin to
>
>awk 'BEGIN {print $1;FS="/"; print $1$3} END BEGIN {print $2; FS="/";
>print $1$3}'
>
>I'm sure that the syntax is wrong but I hope I'm getting the idea
>across.  My Unix in a Nutshell is just not much help.
>
>Thanks.
>
>~F

Got a solution that works for me (the code Kenny provided bailed out
and I don't know enough to troubleshoot it).

sudo rsh $X snapvault status | tail +3 | sed 's/  */\//g' | awk -F"/"
'{print $1$3,$5$7}' | uniq

The sed piece tranlsates all spaces into a single /, which is then
simple to awk against.

I had trouble remembering/finding the syntax for multi-character
replacement with a single character but there it is.  Space is my
replacee, so one space followed by a second with asterisk.  For those
as unitiated as me it means "this character followed by zero or more
of the same".  I used this many moons ago but forgot all about it.

Thanks.

~F

Report this thread to moderator Post Follow-up to this message
Old Post
Faeandar
10-08-04 01:55 AM


Re: relation mapping question
Faeandar wrote:
> On Thu, 07 Oct 2004 23:24:49 GMT, gazelle@yin.interaccess.com (Kenny
> McCormack) wrote:
>
> 
>
>
> Jeezus, I don't even know what ORS is!  :)
>
> Ok, for a follow-up, I realized I can change the spaces between the
> sections into a "/" with sed, but forget the syntax to turn multiple
> spaces into a single "/".  I know it's possible because I did it about
> 4 years ago for some NetBackup stuff.  Anyone remember that little
> piece of trivia?
>
> Btw Kenny, thanks.  I'll be testing this momentarily.
>
> ~F

i know it's a bit off topic but i'll give this one a shot. in sed, try
something like (untested)

s/  */\//g

which will turn any number of spaces (>1) into /

hope this helps,

tom

Report this thread to moderator Post Follow-up to this message
Old Post
Thomas Toth
10-08-04 08:55 AM


Re: relation mapping question

Faeandar wrote:

> I am trying to map a relation from the following line format
>
> hostA:/vol/vol9/dir	hostB:/vol/vol9/hostA_vol9_dir
>
> The relation I want is
>
> hostA:vol9 hostB:vol9	in that format, in a file.
>
> (for those who are familiar with NetApp you will recognize this as a
> snapvault configuration)
>
> My total experience with awk can be sum'd up '{print $whatever.....}'
> but the book is en route.
>
> My guess is I can use multi BEGIN's and END's to define the FS for
> each side of the mapping.  Something akin to
>
> awk 'BEGIN {print $1;FS="/"; print $1$3} END BEGIN {print $2; FS="/";
> print $1$3}'

I can't even imagine where you were coming from with that. In any case,
here y'go:

awk '{for (i=1; i<=NF; i++) {
split($i,T,/[\/:]/)
$i =  T[1] ":" T[4]
}
print
}'

Regards,

Ed.

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
10-08-04 08:55 PM


Re: relation mapping question
On Thu, 07 Oct 2004 23:06:17 +0000, Faeandar wrote:
> I am trying to map a relation from the following line format
>
> hostA:/vol/vol9/dir	hostB:/vol/vol9/hostA_vol9_dir
>
> The relation I want is
>
> hostA:vol9 hostB:vol9	in that format, in a file.

Not exactly clear what your specification is... not my problem...

> (for those who are familiar with NetApp you will recognize this as a
> snapvault configuration)
>
> My total experience with awk can be sum'd up '{print $whatever.....}'
> but the book is en route.

The book would be a good idea. I think you have some misconceptions.

> My guess is I can use multi BEGIN's and END's to define the FS for
> each side of the mapping.  Something akin to
>
> awk 'BEGIN {print $1;FS="/"; print $1$3} END BEGIN {print $2; FS="/";
> print $1$3}'
>
> I'm sure that the syntax is wrong but I hope I'm getting the idea
> across.  My Unix in a Nutshell is just not much help.

No, your fundamental problems is thinking that BEGIN...END are program
blocks in awk. Instead, BEGIN and END are patterns! BEGIN matches at the
very beginning of the awk program execution, before you have read any
input. END matches at the very end of the program, after you have read and
processed all input. awk is a kind of "report writer" that triggers
actions in processing blocks (delimited by {}) according to patterns that
match the input lines. You will have to adjust your thinking.

Read the book. I would have thought there might be some tutorials on the
web? Haven't looked myself. I have a tattered awk book here somewhere.

--
Juhan Leemet
Logicognosis, Inc.


Report this thread to moderator Post Follow-up to this message
Old Post
Juhan Leemet
10-08-04 08:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:52 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.