One line handies

Discussion in 'Ruby' started by Lyndon Samson, Aug 9, 2005.

  1. ------=_Part_1461_20829698.1123542978337
    Content-Type: text/plain; charset=ISO-8859-1
    Content-Transfer-Encoding: quoted-printable
    Content-Disposition: inline

    Ruby is such a sweet language that you can achieve alot with little code

    I'd like to see what 'one-liners' others have come up with.

    here's one I find usefull.

    ruby -e 'puts ENV["path"].downcase.split(";").sort'

    handy for windows but *nix ppl would probably use sed.

    ------=_Part_1461_20829698.1123542978337--
     
    Lyndon Samson, Aug 9, 2005
    #1
    1. Advertising

  2. Lyndon Samson

    Ara.T.Howard Guest

    On Tue, 9 Aug 2005, Lyndon Samson wrote:

    > Ruby is such a sweet language that you can achieve alot with little code
    >
    > I'd like to see what 'one-liners' others have come up with.
    >
    > here's one I find usefull.
    >
    > ruby -e 'puts ENV["path"].downcase.split(";").sort'
    >
    > handy for windows but *nix ppl would probably use sed.


    show your config:

    ruby -r yaml -r rbconfig -e'y Config::CONFIG'

    -a
    --
    ===============================================================================
    | email :: ara [dot] t [dot] howard [at] noaa [dot] gov
    | phone :: 303.497.6469
    | Your life dwells amoung the causes of death
    | Like a lamp standing in a strong breeze. --Nagarjuna
    ===============================================================================
     
    Ara.T.Howard, Aug 9, 2005
    #2
    1. Advertising

  3. Hi --

    On Tue, 9 Aug 2005, Lyndon Samson wrote:

    > Ruby is such a sweet language that you can achieve alot with little code
    >
    > I'd like to see what 'one-liners' others have come up with.
    >
    > here's one I find usefull.
    >
    > ruby -e 'puts ENV["path"].downcase.split(";").sort'
    >
    > handy for windows but *nix ppl would probably use sed.


    Not necessarily, but we would use PATH and ":" :)


    David

    --
    David A. Black
     
    David A. Black, Aug 9, 2005
    #3
  4. On 8/8/05, David A. Black <> wrote:
    > Hi --
    >=20
    > On Tue, 9 Aug 2005, Lyndon Samson wrote:
    >=20
    > > Ruby is such a sweet language that you can achieve alot with little cod=

    e
    > >
    > > I'd like to see what 'one-liners' others have come up with.
    > >
    > > here's one I find usefull.
    > >
    > > ruby -e 'puts ENV["path"].downcase.split(";").sort'
    > >
    > > handy for windows but *nix ppl would probably use sed.

    >=20
    > Not necessarily, but we would use PATH and ":" :)
    >=20
    >=20
    > David
    >=20
    > --=20
    > David A. Black
    >
    >=20
    >
     
    Bruce Woodward, Aug 9, 2005
    #4
  5. Lyndon Samson

    Ara.T.Howard Guest

    On Tue, 9 Aug 2005, David A. Black wrote:

    > Hi --
    >
    > On Tue, 9 Aug 2005, Lyndon Samson wrote:
    >
    >> Ruby is such a sweet language that you can achieve alot with little code
    >>
    >> I'd like to see what 'one-liners' others have come up with.
    >>
    >> here's one I find usefull.
    >>
    >> ruby -e 'puts ENV["path"].downcase.split(";").sort'
    >>
    >> handy for windows but *nix ppl would probably use sed.

    >
    > Not necessarily, but we would use PATH and ":" :)


    cross platform sed-ness:

    harp:~ > ruby -r yaml -e 'y ENV[% PATH ].downcase.split(%r [:;] )'
    ---
    - "."
    - "~/bin"
    - "~/shared/bin"
    - /home/ahoward/bin
    - /usr/local/sbin
    - /usr/sbin
    - /sbin
    - /data/bin
    - /usr/kerberos/bin
    - /usr/local/bin
    - /bin
    - /usr/bin
    - /usr/x11r6/bin
    - /dmsp/reference/bin
    - /usr/local/java/bin

    ;-)

    btw - this is the first use i've ever found for using the %<space> trick...

    -a
    --
    ===============================================================================
    | email :: ara [dot] t [dot] howard [at] noaa [dot] gov
    | phone :: 303.497.6469
    | Your life dwells amoung the causes of death
    | Like a lamp standing in a strong breeze. --Nagarjuna
    ===============================================================================
     
    Ara.T.Howard, Aug 9, 2005
    #5
  6. Lyndon Samson

    Ara.T.Howard Guest

    On Tue, 9 Aug 2005, Ara.T.Howard wrote:

    > On Tue, 9 Aug 2005, David A. Black wrote:
    >
    >> Hi --
    >>
    >> On Tue, 9 Aug 2005, Lyndon Samson wrote:
    >>
    >>> Ruby is such a sweet language that you can achieve alot with little code
    >>>
    >>> I'd like to see what 'one-liners' others have come up with.
    >>>
    >>> here's one I find usefull.
    >>>
    >>> ruby -e 'puts ENV["path"].downcase.split(";").sort'
    >>>
    >>> handy for windows but *nix ppl would probably use sed.

    >>
    >> Not necessarily, but we would use PATH and ":" :)

    >
    > cross platform sed-ness:
    >
    > harp:~ > ruby -r yaml -e 'y ENV[% PATH ].downcase.split(%r [:;] )'


    oops

    harp:~ > ruby -r yaml -e 'y (ENV[% PATH ] || ENV[% path ]).downcase.split(%r [:;] )'


    -a
    --
    ===============================================================================
    | email :: ara [dot] t [dot] howard [at] noaa [dot] gov
    | phone :: 303.497.6469
    | Your life dwells amoung the causes of death
    | Like a lamp standing in a strong breeze. --Nagarjuna
    ===============================================================================
     
    Ara.T.Howard, Aug 9, 2005
    #6
  7. Hi --

    On Tue, 9 Aug 2005, Ara.T.Howard wrote:

    > On Tue, 9 Aug 2005, Ara.T.Howard wrote:
    >
    >> On Tue, 9 Aug 2005, David A. Black wrote:
    >>
    >>> Hi --
    >>>
    >>> On Tue, 9 Aug 2005, Lyndon Samson wrote:
    >>>
    >>>> Ruby is such a sweet language that you can achieve alot with little code
    >>>>
    >>>> I'd like to see what 'one-liners' others have come up with.
    >>>>
    >>>> here's one I find usefull.
    >>>>
    >>>> ruby -e 'puts ENV["path"].downcase.split(";").sort'
    >>>>
    >>>> handy for windows but *nix ppl would probably use sed.
    >>>
    >>> Not necessarily, but we would use PATH and ":" :)

    >>
    >> cross platform sed-ness:
    >>
    >> harp:~ > ruby -r yaml -e 'y ENV[% PATH ].downcase.split(%r [:;] )'

    >
    > oops
    >
    > harp:~ > ruby -r yaml -e 'y (ENV[% PATH ] || ENV[% path
    > ]).downcase.split(%r [:;] )'


    I'm not sure I get why you'd need all this (YAML, the space trick, the
    two cases). Does this:

    ruby -e 'puts ENV["PATH"].downcase.split(/[:;]/).sort'

    not work on all platforms? Or are there quote/escaping issues?


    David

    --
    David A. Black
     
    David A. Black, Aug 9, 2005
    #7
  8. Lyndon Samson

    Bill Kelly Guest

    From: "David A. Black" <>
    > Does this:
    >
    > ruby -e 'puts ENV["PATH"].downcase.split(/[:;]/).sort'
    >
    > not work on all platforms? Or are there quote/escaping issues?


    DOS (cmd.exe) will need the double- and single-quotes swapped:

    ruby -e "puts ENV['PATH'].downcase.split(/[:;]/).sort"

    But... the colon will cause probs, because of windoze paths
    like C:\blah\blah ...


    Regards,

    Bill
     
    Bill Kelly, Aug 9, 2005
    #8
  9. Bill Kelly wrote:
    > From: "David A. Black" <>
    > > Does this:
    > >
    > > ruby -e 'puts ENV["PATH"].downcase.split(/[:;]/).sort'
    > >
    > > not work on all platforms? Or are there quote/escaping issues?

    >
    > DOS (cmd.exe) will need the double- and single-quotes swapped:
    >
    > ruby -e "puts ENV['PATH'].downcase.split(/[:;]/).sort"


    Did you try it without swapping the quotes?

    Unlike awk, mawk, and gawk, Ruby under DOS accepts single quotes as
    argument wrappers. However, if the string contains |, <, or >, then
    you had better use double quotes.
     
    William James, Aug 9, 2005
    #9
  10. Lyndon Samson

    Bill Kelly Guest

    From: "William James" <>
    >
    > Bill Kelly wrote:
    > > DOS (cmd.exe) will need the double- and single-quotes swapped:
    > >
    > > ruby -e "puts ENV['PATH'].downcase.split(/[:;]/).sort"

    >
    > Did you try it without swapping the quotes?
    >
    > Unlike awk, mawk, and gawk, Ruby under DOS accepts single quotes as
    > argument wrappers. However, if the string contains |, <, or >, then
    > you had better use double quotes.


    Whoa... ! Thanks. Makes me wonder if that always been true,
    even back when the standard Ruby distribution for windows was
    cygwin based? Or maybe I got so accustomed to

    perl -e 'print "huzzah\n"'
    Can't find string terminator "'" anywhere before EOF at -e line 1.

    I never tried it on ruby!


    Thanks,

    Regards,

    Bill
     
    Bill Kelly, Aug 9, 2005
    #10
  11. Hi,

    At Tue, 9 Aug 2005 09:01:45 +0900,
    David A. Black wrote in [ruby-talk:151306]:
    > I'm not sure I get why you'd need all this (YAML, the space trick, the
    > two cases). Does this:
    >
    > ruby -e 'puts ENV["PATH"].downcase.split(/[:;]/).sort'
    >
    > not work on all platforms? Or are there quote/escaping issues?


    No. /home/foo/BIN and /home/foo/bin are different directories
    on case-sensitive filesystems.

    ruby -e "puts ENV['PATH'].split(File::pATH_SEPARATOR).sort"

    --
    Nobu Nakada
     
    nobuyoshi nakada, Aug 9, 2005
    #11
  12. Lyndon Samson wrote:
    > Ruby is such a sweet language that you can achieve alot with little
    > code
    >
    > I'd like to see what 'one-liners' others have come up with.
    >
    > here's one I find usefull.
    >
    > ruby -e 'puts ENV["path"].downcase.split(";").sort'
    >
    > handy for windows but *nix ppl would probably use sed.


    http://www.rubygarden.org/ruby?OneLiners
    http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/81834

    You'll find more with http://www.google.com/search?q=ruby one liners

    Kind regards

    robert
     
    Robert Klemme, Aug 9, 2005
    #12
  13. Hi!

    At Tue, 9 Aug 2005 12:18:13 +0900, nobuyoshi nakada wrote:
    > At Tue, 9 Aug 2005 09:01:45 +0900,
    > David A. Black wrote in [ruby-talk:151306]:
    > > ruby -e 'puts ENV["PATH"].downcase.split(/[:;]/).sort'

    >
    > No. /home/foo/BIN and /home/foo/bin are different directories on
    > case-sensitive filesystems.
    >
    > ruby -e "puts ENV['PATH'].split(File::pATH_SEPARATOR).sort"



    Follows version that makes PATH case-insensitive. Works even if you
    have several environment variables that match /^path$/ (possible under
    Linux et. al.) their content is printed one after another).

    ruby -e 'ENV.keys.grep(/^path$/i).each { |x| puts ENV[x].split(File::pATH_SEPARATOR)}'

    Josef 'Jupp' SCHUGT
    --
    Terrorism is the systematic use of violence and brutality as a means of
    gaining some political end. So the "War on Terrorism" is a failure if
    it increases violence and brutality and even may be terrorism by itself
    if some well-known incidents turn out not to be singular ones. :-|
     
    Josef 'Jupp' SCHUGT, Aug 10, 2005
    #13
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hugo
    Replies:
    10
    Views:
    1,343
    Matt Humphrey
    Oct 18, 2004
  2. news.frontiernet.net
    Replies:
    6
    Views:
    1,141
    news.frontiernet.net
    Apr 16, 2004
  3. kaushikshome
    Replies:
    4
    Views:
    795
    kaushikshome
    Sep 10, 2006
  4. scad
    Replies:
    23
    Views:
    1,193
    Alf P. Steinbach
    May 17, 2009
  5. Merciadri Luca
    Replies:
    4
    Views:
    834
Loading...

Share This Page