べすとえふぉーと

プログラミング等のノート 

シェル

2つのディレクトリにあるファイルを比較して差分のあるファイルを表示

dir1とdir2がパス diff -qr dir1/ dir2/ | grep "Files" | cut -d ' ' -f2

パイプで渡された文字の前に特定の文字列をつける

16進の値が渡ってきたとして、前に0xをつける echo "A2" | awk '{print "0x" $1}'

ディレクトリ内にあるファイル名だけを抽出

find dir/ -type f | awk -F "/" '{ print $NF }'dirが抽出対象のディレクトリ

gitのログから変更したファイルを抽出してcsvに出力

git log $starthash...$endhash --name-only \ | grep -e "src" -e "config" \ | grep -v "exclude_string_1" \ | grep -v "exclude_string_2" \ | sort \ | uniq \ | xargs find > ../pathlist.txt 2>/dev/null ; cat ../pathlist.txt \ | awk -F "/" '{ pr…

sedで文字列置換

普通に置き換え echo hogepiyohoge | sed -e "s/piyo/hoge/g"空白に置き換え echo hogepiyohoge | sed -e "s/piyo//g"

sedで#が入ってる行を削除、空白行も削除する

例はhttpd.conf 動作は未確認 cat httpd.conf | sed '/\#/d' | sed '/^$/d' > out_httpd.conf

cut,sedの使い方メモ

最初の11文字を除去 cut -c 11-2文字目以降を取り出す cut -c 2-ダブルクォートを除去 sed -e "s/\"//g"