for i in `cat hostnames.list`
do
nslookup ${i}
done > names.txt
I'm left with...
host1name.com
10.10.10.1
host2name.com
10.10.10.2
host3name.com
10.10.10.3
I've been using an uppercase J in vi to manually move the hostname's
IP address up onto the same line as it's hostname.
I'd love to automate this and thought awk's sub() function might be
the key but I can't even get it to sub X for Y, much less locate
"hostname.com$" and then send in a "J" (ascii 074). Any thoughts/
suggestions will be appreciated. Tks /n
ORS=NR%2?" ":"\n"
Yes, that's the whole program!
Hi Kenny. Thanks for the quick reply.
I've been playing with awk for a while now and was beginning to
question my sanity until I read a post by Ed Morton about awk in
Solaris. I'm a Solaris admin and didn't know awk was broken in
Solaris. I tried nawk on some stuff I thought should have worked but
didn't, and it worked! Make me crazy.
This is not to say that any of my stuff was as slick, short, or simple
as yours and for that, I thank you.
Rgds,
/n
or:
ORS=NR%2?FS:RS
Fore!
Ed.
Cute. I like it.
>Fore!
Indeed!
I'm sure I didn't invent it, I probably just picked it up somewhere, but the
thing I like about it especially is how much awk it covers in such a short
example. I mean in those 14 characters we've introduced output record
separators, field separators, input record separators, the condition-action
paradigm, ternary operators, and default actions - that's almost a significant
concept every 2 characters! Explaining it would make a good interview exam
question for awk programmers ;-).
Ed.
I've used that idiom at least in a posting back in 2007 (and mayve
even
earlier than that). Anyway, whenever that was; I haven't seen it
before
I used it. So, if no one complains I'd claim being the inventor. :-}
Janis
> [...]
I'm 98% sure that I personally invented the basic idea (ORS=... as the
pattern, with no action - i.e., default action). Ed's enhancement was
using FS and RS instead of hardcoding space and newline. It's nice for
two reasons:
1) Saves a few golf strokes
2) Is more "portable" (or "logical", if you look at it that way) in
that if FS and RS had been assigned non-default values, they
would be used.
Also, as he says, it is a very instructive 14 characters of AWK code.
Yes, I seem to recall so, as well; that you've invented using ORS
without explicite action.
My idiom (at that time) was using the builtin variables instead of
string constants.
Actually (in the mentioned posting) this expression
BEGIN{OFS="\t"}{ORS=NR%2?OFS:RS)}$1=$1
which, today, wouldn't make a birdy. ;-)
Janis
Well, someone had better patent this quick before Bill Gates sees it and makes
more millions...
Ed.
:-)
My _hope_ is that material that was published in a public place (like
Usenet) becomes hard to patent. But legislation seems to vary a lot
across national borders, and, frankly, I am unsure whether that's
effectively true in any country at all, nowadays.
Janis
>
> Ed.