ruby等效perl命令用于替换文件中的换行符?

时间:2017-04-08 01:35:11

标签: ruby perl

我试图获得这个perl命令的等效ruby命令

这是我的档案

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

这是我的参考perl命令:

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

我正在使用这个ruby命令,但它不起作用:

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

请帮帮我

2 个答案:

答案 0 :(得分:3)

$video_id=$v->getId();
$url="image.jpg";
    $client->setDefer(true);
    $thumb = $youtube->thumbnails->set($video_id);
    $media = new \Google_Http_MediaFileUpload(
        $client,
        $thumb,
        'image/png',
        null,
        true,
        $chunkSizeBytes
    );

    $media->setFileSize(filesize($url));
    // Read the media file and upload it chunk by chunk.
    $status = false;
    $handle = fopen($url, "rb");
    while (!$status && !feof($handle)) {
      $chunk = fread($handle, $chunkSizeBytes);
      $status = $media->nextChunk($chunk);
    }

    fclose($handle);

    // If you want to make other calls after the file upload, set setDefer back to false
    $client->setDefer(false);

答案 1 :(得分:2)

  • puts打印换行符;使用不打印换行符的print
  • 使用$F[0],未传递换行符,您无需删除换行符
ruby -a -ne 'print $F[0].gsub(/\r?$/, ";")' bbb