ruby and egrep command line

U

Une bévue

if from a ruby script, i do :

server="/Volumes/HDX/Users/yvon/MacSOUP_news.individual.net/individual"

nntp=`egrep -i -o --binary-files=text -e "news\.\w+\.\w+"
"#{server}/..namedfork/rsrc"`.chomp

p "nntp = " + nntp


i get "" (empty answer)


if i write a bash script "getNntpAddress.sh" with the following :

#!/bin/bash

nntp=`egrep -i -o --binary-files=text -e "news\.\w+\.\w+"
$1/..namedfork/rsrc`
echo $nntp


and use it from ruby by :

nntp=`/Users/yvon/work/RubyCocoa/MacSOUPSwitcher/map/getNntpAddress.sh
#{server}`.chomp

p "nntp = " + nntp


i get the correct answer "nntp = news.individual.net"
 
R

Robert Klemme

Une said:
if from a ruby script, i do :

server="/Volumes/HDX/Users/yvon/MacSOUP_news.individual.net/individual"

nntp=`egrep -i -o --binary-files=text -e "news\.\w+\.\w+"
"#{server}/..namedfork/rsrc"`.chomp

p "nntp = " + nntp


i get "" (empty answer)


if i write a bash script "getNntpAddress.sh" with the following :

#!/bin/bash

nntp=`egrep -i -o --binary-files=text -e "news\.\w+\.\w+"
$1/..namedfork/rsrc`
echo $nntp


and use it from ruby by :

nntp=`/Users/yvon/work/RubyCocoa/MacSOUPSwitcher/map/getNntpAddress.sh
#{server}`.chomp

p "nntp = " + nntp


i get the correct answer "nntp = news.individual.net"

There's really no need to call egrep from Ruby. This makes things more
complicated and less efficient than needed. Why don't you just do this:

server="/Volumes/HDX/Users/yvon/MacSOUP_news.individual.net/individual"
nntp=File.read("#{server}/..namedfork/rsrc")[/news\.\w+\.\w+/]

p "nntp = " + nntp

Kind regards

robert
 
U

Une bévue

Robert Klemme said:
There's really no need to call egrep from Ruby. This makes things more
complicated and less efficient than needed. Why don't you just do this:

server="/Volumes/HDX/Users/yvon/MacSOUP_news.individual.net/individual"
nntp=File.read("#{server}/..namedfork/rsrc")[/news\.\w+\.\w+/]

p "nntp = " + nntp

'cause i didn't think about that solution which works great !

thanks a lot
 

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
474,206
Messages
2,571,069
Members
47,677
Latest member
MoisesKoeh

Latest Threads

Top