sed 改行文字をスペースに置き換える

sed 改行文字をスペースに置き換える

sedを使用して改行文字を別の文字に置き換えるには?

入力する:

 I cannot conceive that anybody will    
 require multiplications at the rate of 
 40,000 or even 4,000 per hour ...      

 -- F. H. Wales (1936)                  

希望の出力:

I cannot conceive that anybody will require multiplications at the rate of 40,000 or even 4,000 per hour ...  -- F. H. Wales (1936)

私は試した:

> pbpaste | sed 's/\n/ /g' 

ただし、入力と同じ結果が出力されます。私はそれを確認し、cat -ev期待どおりに印刷したので、これが改行文字であることを知っています。$

これを行うためのより良いコマンドはありますか?


これにより、新しい行の間に余分なスペースが表示されます。私も削除したいです。それで、空白のある文章と同じです。

> pbpaste | cat -ev
 I cannot conceive that anybody will    $
 require multiplications at the rate of $
 40,000 or even 4,000 per hour ...      $
                                        $
 -- F. H. Wales (1936)                  ⏎   

ベストアンサー1

trそれはおそらく仕事のためのより良いツールでしょう。以下を試してください

pbpaste | tr '\n' ' '

あなたの入力に基づいて、次のような結果が得られます。

I cannot conceive that anybody will require multiplications at the rate of 40,000 or even 4,000 per hour ...  -- F. H. Wales (1936) 

おすすめ記事