7stud2
(7stud --)
6 November 2012 22:21
1
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.
···
--
Posted via http://www.ruby-forum.com/ .
Robert_K1
(Robert K.)
6 November 2012 22:39
2
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
···
On Tue, Nov 6, 2012 at 11:21 PM, Ferdous ara <lists@ruby-forum.com> wrote:
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 ??
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
7stud2
(7stud --)
6 November 2012 23:18
3
require 'stringio'
f = StringIO.new(<<ENDOFSTRING)
hello world
up down stuff here
up down aenet 4a 5a 6a
aenet up down 4b 5b 6b
ENDOFSTRING
target_column = 6
results = f.grep(/up down/).grep(/aenet/)
results.each {|line| puts line.split[target_column - 1]}
--output:--
6a
6b
···
--
Posted via http://www.ruby-forum.com/ .
7stud2
(7stud --)
6 November 2012 23:39
4
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.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"
···
--
Posted via http://www.ruby-forum.com/ .
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 Tue, Nov 6, 2012 at 4:21 PM, Ferdous ara <lists@ruby-forum.com> wrote:
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.
--
Posted via http://www.ruby-forum.com/\ .
7stud2
(7stud --)
6 November 2012 22:54
6
. 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 <command>.
configure systemconsole
^
syntax error, expecting <command>.
{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
···
--
Posted via http://www.ruby-forum.com/ .
7stud2
(7stud --)
6 November 2012 23:31
7
--output:--
ae40.0
ae30.0
HI thanks
only problem is, i want output like
ae40.0 ae30.0
in one line ..
Thanks
···
--
Posted via http://www.ruby-forum.com/\ .
results =
...
results << $1 if md
...
puts results.join " "
···
On Nov 6, 2012, at 15:39 , 7stud -- <lists@ruby-forum.com> wrote:
if md
results << $1 << " "
end
end
p results.rstrip
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 <tamouse.lists@gmail.com> wrote:
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 Tue, Nov 6, 2012 at 4:21 PM, Ferdous ara <lists@ruby-forum.com> wrote:
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.
--
Posted via http://www.ruby-forum.com/\ .
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 <tamouse.lists@gmail.com> wrote:
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 > <tamouse.lists@gmail.com> wrote:
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 Tue, Nov 6, 2012 at 4:21 PM, Ferdous ara <lists@ruby-forum.com> wrote:
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.
--
Posted via http://www.ruby-forum.com/\ .
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 <tamouse.lists@gmail.com> wrote:
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 > <tamouse.lists@gmail.com> wrote:
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 >> <tamouse.lists@gmail.com> wrote:
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 Tue, Nov 6, 2012 at 4:21 PM, Ferdous ara <lists@ruby-forum.com> wrote:
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.
--
Posted via http://www.ruby-forum.com/\ .