Need to step through text in Variable

  • Thread starter jackster the jackle
  • Start date
J

jackster the jackle

My script starts out by connecting to another machine via SSH and
reading the hosts file into a variable:

z = `ssh -l username -i /home/username/.ssh/id_rsa 10.1.1.1 cat
/etc/hosts`

Normally if the hosts file was on my local machine, I would be able to
step through the contents of the file line by line and make decisions
based on REGEX using the file open commands.

I don't want to have to write the contents of my variable to a file and
then open and step through it that way.

What would be the best way to step through my z variable line by line
and match on the content with REGEX?

thanks

jack
 
J

Jean-Julien Fleck

Hello Jack
What would be the best way to step through my z variable line by line
and match on the content with REGEX?

z.split(/\n/).each do |line|
...
end

should do what you are looking for.

Cheers,

--=20
JJ Fleck
PCSI1 Lyc=E9e Kl=E9ber
 
R

Robert Klemme

My script starts out by connecting to another machine via SSH and
reading the hosts file into a variable:

z = `ssh -l username -i /home/username/.ssh/id_rsa 10.1.1.1 cat
/etc/hosts`

Normally if the hosts file was on my local machine, I would be able to
step through the contents of the file line by line and make decisions
based on REGEX using the file open commands.

I don't want to have to write the contents of my variable to a file and
then open and step through it that way.

What would be the best way to step through my z variable line by line
and match on the content with REGEX?

`ssh ...`.each_line do |line|
...
end

Kind regards

robert
 
R

Robert Klemme

2010/3/16 jackster the jackle said:
thanks alot Jean-Julien....that works perfectly!

Somehow my response to the newsgroup is delayed. You do not need
#split. You can do

`ssh ...`.each_line do |line|
...
end

This works at least in 1.8.7 and 1.9, probably also in 1.8.6.

Kind regards

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top