Came back to playing with this. I found that just a plan old sort
does the sort as I need. RudiC, I think you were trying to point me in that direction previously with your questions about why use -k5
and -g
After presenting this to the boss, he really liked it and wants to get it implemented in the system for everyone to use, but not without a few changes. This brings me back to a previous problem and introduced new issues (of course, new features = new problems to debug).
What I have currently is:
cpever () {
awk '/JUNOS/ && /boot/ {sub ("/show.version", "", FILENAME); print $5 " " FILENAME}' ~/svn/nw_config_data/*cpe.domain.net/show.version | sort
}
Which then outputs:
[10.0R4.7] /home/clmbn-eng2/a/rwalker/svn/nw_config_data/device-r0.cpe.domain.net
I've been trying to strip this out out /home/clmbn-eng2/a/rwalker/svn/nw_config_data/
so that my output looks like this instead [10.0R4.7] device-r0.cpe.domain.net
but I can't get it right. To test it I replaced "/show.version"
with the full path, and that got rid of it, but left the /show.version
.
RudiC, you had mentioned another sub(...)
but I failed horribly at implementing it. I tried setting it up like this:
cpever () {
awk '/JUNOS/ && /boot/ {sub ("/show.version", "", FILENAME); sub ("/home/clmbn-eng2/a/rwalker/svn/nw_config_data/"); print $5 " " FILENAME}' ~/svn/nw_config_data/*cpe.domain.net/show.version | sort
}
but I get this error, and I just am not sure how to do it right
awk: syntax error at source line 1
context is
/JUNOS/ && /boot/ {sub ("/show.version", "", FILENAME); sub >>> ("/home/clmbn-eng2/a/rwalker/svn/nw_config_data/") <<<
awk: illegal statement at source line 1
Notice that in the path after the /a/
is my username. If I want this to work for everyone, I can't have my username there. So, I tried setting it up like this "/home/clmbn-eng2/a/*/svn/nw_config_data/"
to use the *
as a wildcard, but that doesn't work and just shows me the full path again. I checked the /home/clmbn-eng2/a/
directory and I see all the different users there, so I'm wondering if maybe in this instance *
doesn't work as a wildcard search? If that's the case, how do I wildcard it to make this command friendly for everyone?
Once I sort out how to wildcard that part of the directory, and remove the filepath up to the device name AND the "/show.version"
I can move on to what the boss wants next. He wants one command that contains all 3 cpe subdomains we have that can be hit with a variable like -c
, -e
, or -o
. I'm still researching how to do all the different variables and stuff with awk, so for now I have this setup as a starting point for after I learn some more and figure out the multiple subs to strip out stuff I don't want to show:
cver () {
#Need a help defined by -h which would show the different variables available to the user. Also suggest grep | "xx" to find specific versions
#cver without any variables should kick back -h message, if possible, to user that they need to define a variable such as -c, -e, -o
#cver without those variables is no fun having everything shown to you at once
awk '/JUNOS/ && /boot/ {sub ("/show.version", "", FILENAME); print $5 " " FILENAME}' ~/svn/nw_config_data/*cpe.domain.net/show.version | sort
#I want cpe to be accessed by -c
#Example: cver -c
#
awk '/JUNOS/ && /boot/ {sub ("/show.version", "", FILENAME); print $5 " " FILENAME}' ~/svn/nw_config_data/*cpe2.domain.net/show.version | sort
#I want cpe2 to be accessed by -e
#Example: cver -e
#
awk '/JUNOS/ && /boot/ {sub ("/show.version", "", FILENAME); print $5 " " FILENAME}' ~/svn/nw_config_data/*cpe3.domain.net/show.version | sort
#I want cpe3 to be accessed by -o
#Example: cver -o
}