Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageIn 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]
}
}
Post Follow-up to this messageOn 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
Post Follow-up to this messageOn 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
Post Follow-up to this messageFaeandar 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
Post Follow-up to this message
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.
Post Follow-up to this messageOn 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.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.