Ruby equivalent perl command to replace newlines from file?

I am trying to get the equivalent ruby ​​command of this perl command

this is my file

centroid
100x50+0+0
28x22+39+9
19x22+68+12
15x23+5+13
15x24+22+10

      

This is my perl recommendation command:

perl -pe 's/\r?\n/,/'  bbb

      

I am using this ruby ​​command but it doesn't work:

 ruby -a  -ne   'puts $F[0].gsub(/\r?\n/, ";")' bbb

      

Please help me

+3


source to share


2 answers


  • puts

    printing a new line; use print

    that doesn't print a newline.
  • Using $F[0]

    , no newline is passed, you don't need to remove the newline



ruby -a -ne 'print $F[0].gsub(/\r?$/, ";")' bbb

      

+2


source


% ruby -p -e 'sub(/\r?\n/, ",")' bbb
centroid,100x50+0+0,28x22+39+9,19x22+68+12,15x23+5+13,15x24+22+10,

      



+3


source







All Articles