それマグで!

知識はカップより、マグでゆっくり頂きます。 takuya_1stのブログ

習慣に早くから配慮した者は、 おそらく人生の実りも大きい。

コマンド 実行結果から改行を取り除いて一行にする。

コマンドの実行結果を一行にまとめたり、一行になったものを複数行に分割したいことが有りますよね

tr コマンドで置換

tr コマンドは translate word で文字を移動させるものですが。

takuya@rena:~/Downloads$ echo "abcdefgabcabca" | tr abc xyz
xyzdefgxyzxyzx

改行を置換

以下のコマンドは、with オプションを一覧するが、そのままだと使えない。

takuya@rena:~/Desktop$ brew info ffmpeg | grep ^--with | grep -v ^--without
--with-fdk-aac
--with-ffplay
--with-freetype
--with-frei0r
--with-libass
--with-libbluray
--with-libcaca
--with-libquvi
--with-libvo-aacenc
--with-libvorbis
--with-libvpx
--with-opencore-amr
--with-openjpeg
--with-openssl
--with-opus
--with-rtmpdump
--with-schroedinger
--with-speex
--with-theora
--with-tools

そこで一行にまとめる。

tr を使って複数行を一行にまとめる。

brew info ffmpeg | grep ^--with | grep -v ^--without  | tr '\n' ' '
--with-fdk-aac --with-ffplay --with-freetype --with-frei0r --with-libass --with-libbluray --with-libcaca --with-libquvi --with-libvo-aacenc --with-libvorbis --with-libvpx --with-opencore-amr --with-openjpeg --with-openssl --with-opus --with-rtmpdump --with-schroedinger --with-speex --with-theora --with-tools

sed でもできるけど。。。sedGNU sedOSXBSD sed で動作が違うから面倒だよね。