LoginSignup
0
1

More than 5 years have passed since last update.

テキストファイルのみ抽出して改行コードを変換するワンライナーコマンド

Posted at

概要

シェル上から、テキストファイルの拡張子を個別に指定して、改行コードをCRLF→LFに変換するワンライナーコードを紹介します。

コード

$ find /path/to/directory -type f \( -name \*.php -or -name \*.js -or -name \*.txt -or -name \*.html -or -name \*.css \) -exec dos2unix {} \;

改行して見やすく

$ find /path/to/directory \
    -type f \
    \( \
        -name \*.php \
        -or \
        -name \*.js \
        -or \
        -name \*.txt \
        -or \
        -name \*.html \
        -or \
        -name \*.css \
    \) 
    -exec dos2unix {} \;

説明

findコマンドのオプションで特定の拡張子を指定し、それらをdos2unixコマンドに渡しています。
それだけといえばそれだけです。
該当のテキストファイルを上書きして保存するので、要注意です。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1