1827701 Members
3048 Online
109967 Solutions
New Discussion

combinig o/p

 
SOLVED
Go to solution
Soul_1
Respected Contributor

combinig o/p

Hi all,

i wrote one script to get the node details.

#!/usr/bin/sh
#Script to check the node details
Node=$(/opt/OV/bin/ovtopodump -lr|grep "NODE LABEL"|awk '{print $3}')
Int=$(/opt/OV/bin/ovtopodump -lr|grep "NUMBER OF INTERFACES")
Detail="$Node $Int"
echo "$Detail \c\n"
_______________________________
The o/p of this command is will be
Node=$(/opt/OV/bin/ovtopodump -lr|grep "NODE LABEL"|awk '{print $3}')

xyz.co.in
yyy.co.in
sss.co.in
ttt.co.in

and o/p of second command Int=$(/opt/OV/bin/ovtopodump -lr|grep "NUMBER OF INTERFACES")
is
interfaces 30
interfaces 120
interfaces 12
interfaces 44

what is my req is i want to display the o/p in one line

i.e
xyz.co.in interfaces 30
yyy.co.in interfaces 120
sss.co.in interfaces 12

but i am getting o/p as
xyz.co.in
yyy.co.in
sss.co.in
ttt.co.in interfaces 30
interfaces 120
interfaces 12
interfaces 44


please guide me to achieve this .


Thanks to all in advance



12 REPLIES 12
Kapil Jha
Honored Contributor

Re: combinig o/p

there is ery simple utility called paste

paste file1 file2

outpur will be the one you want.

BR,
Kapil+

I am in this small bowl, I wane see the real world......
Soul_1
Respected Contributor

Re: combinig o/p

Hi ,

Thanks for the information.
It would be helpful if we combine the o/p without redirecting the result to another one and combibining it.


any way that was working.Thanks Once again
Kapil Jha
Honored Contributor

Re: combinig o/p

not sure but u can do like

Detail= paste $Node $Int
echo "$Detail \c\n"


this should work.


BR,
Kapil+
I am in this small bowl, I wane see the real world......
Soul_1
Respected Contributor

Re: combinig o/p

Hi,

It is not working, as it is not able to find the files.


Thanks & Regards,
Dennis Handly
Acclaimed Contributor

Re: combinig o/p

>It would be helpful if we combine the output without redirecting the result to another one and combining it.

You can probably do that if you use awk on the output of:
/opt/OV/bin/ovtopodump -lr | grep -e "NODE LABEL" -e "NUMBER OF INTERFACES"

Can you provide a sample of that that looks like?
TARUN SHARMA_1
Advisor

Re: combinig o/p

Just give a small o/p of (/opt/OV/bin/ovtopodump -lr to understand it better.
Sr Tech Lead
Tech Mahindra
Data Canter Tubli Bahrain
Viktor Balogh
Honored Contributor

Re: combinig o/p

try something like this:

# /opt/OV/bin/ovtopodump -lr |
awk '/NODE LABEL/ {printf $3"\t"}
/NUMBER OF INTERFACES/ {print $0}'

maybe it's not perfect because it is untested. But there's no need to run ovtopodump twice and grep can also be done with awk. Tailor it to your own needs.
****
Unix operates with beer.
Dennis Handly
Acclaimed Contributor

Re: combinig o/p

>Viktor: try something like this:

Assuming they come out in that order, you could also use a variable so you only have one print:
... | awk '
/NODE LABEL/ { NODE = $3 }
/NUMBER OF INTERFACES/ { print NODE, $0 }'
Soul_1
Respected Contributor

Re: combinig o/p

hi

Thanks all,

can you please tell me how this command works

1. /opt/OV/bin/ovtopodump -lr|awk '/NODE LABEL/ { NODE = $3 } /NUMBER OF INTERFACES/ { print NODE, $0 }'

2.
/opt/OV/bin/ovtopodump -lr | awk '/NODE LABEL/ {printf $3"\t"}/NUMBER OF INTERFACES/ {print $0}'

It would be great helpful if you explain how this works.

Thanks a lot

both are giving the desired o/p.
Dennis Handly
Acclaimed Contributor
Solution

Re: combinig o/p

>can you please tell me how this command works
>1. awk '/NODE LABEL/ { NODE = $3 } /NUMBER OF INTERFACES/ { print NODE, $0 }'

This saves field3 of every line that has "NODE LABEL". When it finds a line with "NUMBER OF INTERFACES", it first prints the saved NODE, then a space (the variable OFS), then the current line.

>2.awk '/NODE LABEL/ {printf $3"\t"}/NUMBER OF INTERFACES/ {print $0}'

This finds the same two lines. For the first, it prints field3, then a tab. For the second, it prints the line, appended to the first printf (that doesn't have a newline).

Both depend on the ordering of the original two lines.
Viktor Balogh
Honored Contributor

Re: combinig o/p


awk '/search_pattern/ {do this if pattern found}'

with the 'print' awk statement you can write the n'th field by $n. The fields are separated by whitespaces in default.

so the following means:

awk '/NODE LABEL/ {printf $3"\t"}
/NUMBER OF INTERFACES/ {print $0}'

if "NODE LABEL" is found in the line, print the 3rd field, and if "NUMBER OF INTERFACES" matches print the whole line (that's $0)

And do not forget about the quotes (') all around the awk statement, without these the words with $ would be substituted by your shell.

The other query is the same, I hope you can figure that out.
****
Unix operates with beer.
Soul_1
Respected Contributor

Re: combinig o/p

Thanks to all