Putting values in one lines

Hi,
Dont know how to explain this.

example , i am doing this

output=cat #{file} | grep "up down" | grep "aenet" | awk '{print $6}'
puts output

So i get this
ae40.0
ae30.0

But i want to output like ae40.0 ae30.0

how can i achieve this ??

Thanks for your help.

On Tue, Nov 6, 2012 at 11:21 PM, Ferdous ara [email protected]
wrote:

So i get this
ae40.0
ae30.0

But i want to output like ae40.0 ae30.0

how can i achieve this ??

First I’d start by not using shell tools for this in a Ruby script (and
btw. the cat is useless). Then we’d need to know the input to come up
with
suggestions.

Cheers

robert

. Then we’d need to know the input to come up

Hi , the output is coming from a router

and the output has too much rough data , thats why i was using BAck tick

example

spawn

— JUNOS xxxxx built 2012-03-17 18:55:36 UTC
{master:10

— JUNOS xxxxxbuilt 2012-03-17 18:55:36 UTC
{master:10}

syntax error, expecting .
configure systemconsole
^
syntax error, expecting .

{master:10
set output

xe-0/0/2.0 up up aenet --> ae1.0
xe-0/0/3 up up
xe-0/0/3.0 up up aenet --> ae1.0

xe-10/0/6.0 up down aenet --> ae40.0
xe-24/0/3.0 up down aenet --> ae30.0

then…

what i am after is like
xe-10/0/6.0 up down aenet --> ae40.0

Thanks for your help

–output:–
ae40.0
ae30.0

HI thanks

only problem is, i want output like

ae40.0 ae30.0

in one line …

Thanks

require ‘stringio’

f = StringIO.new(<<ENDOFSTRING)
xe-0/0/2.0 up up aenet --> ae1.0
xe-0/0/3 up up
xe-0/0/3.0 up up aenet --> ae1.0

xe-10/0/6.0 up down aenet --> ae40.0
xe-24/0/3.0 up down aenet --> ae30.0
ENDOFSTRING

results = “”

f.each do |line|
md = line.match(/
up
\s*
down
\s*
aenet
.?
–>
\s

(.*)
\n
\z
/xms)

if md
results << $1 << " "
end
end

p results.rstrip

–output:–
“ae40.0 ae30.0”

require ‘stringio’

f = StringIO.new(<<ENDOFSTRING)
xe-0/0/2.0 up up aenet --> ae1.0
xe-0/0/3 up up
xe-0/0/3.0 up up aenet --> ae1.0

xe-10/0/6.0 up down aenet --> ae40.0
xe-24/0/3.0 up down aenet --> ae30.0
ENDOFSTRING

target_column = 6

results = f.grep(/up \s* down \s* aenet/xms)
results.each {|line| puts line.split[target_column - 1]}

–output:–
ae40.0
ae30.0

If you’re hoping to do a pure ruby implementation of this, heed the
others.

If you just need the values, here’s the awk:

awk ‘BEGIN { ORS="" } /up.*down.*aenet/ { print $6 }’ file…

or,

awk -v ORS=’’ ‘/up.*down.*aenet/ { print $6 }’ file…

(you don’t need the cat or either grep)

On Nov 6, 2012, at 15:39 , 7stud – [email protected] wrote:

if md
results << $1 << " "
end
end

p results.rstrip

results = []


results << $1 if md

puts results.join " "

Ok, well, pure ruby:

lines = IO.readlines(file)
lines.each do |l|
if l.match(/up\s+down\s+aenet/)
print l.split[5], " "
end
end
print “\n”

On Tue, Nov 6, 2012 at 7:37 PM, tamouse mailing lists

Okay: one line:

puts IO.readlines(“data”).grep(/up\s+down\s+aenet/).map{|l|
l.split[5]}.join " "

On Tue, Nov 6, 2012 at 10:11 PM, tamouse mailing lists

Ok, more compact:

output = []
IO.readlines(“data”).map{|l| output << l.split[5] if
l.match(/up\s+down\s+aenet/) }
puts output.join " "

On Tue, Nov 6, 2012 at 8:15 PM, tamouse mailing lists