この質問に基づいてファイルをグループ化し、awkコマンドにパイプします
私はこのようなファイルのセットを持っています:-
-rw-r--r-- 1 root root 497186 Apr 21 13:17 2012_03_25
-rw-r--r-- 1 root root 490558 Apr 21 13:17 2012_03_26
-rw-r--r-- 1 root root 488797 Apr 21 13:17 2012_03_27
-rw-r--r-- 1 root root 316290 Apr 21 13:17 2012_03_28
-rw-r--r-- 1 root root 490081 Apr 21 13:17 2012_03_29
-rw-r--r-- 1 root root 486621 Apr 21 13:17 2012_03_30
-rw-r--r-- 1 root root 490904 Apr 21 13:17 2012_03_31
-rw-r--r-- 1 root root 491788 Apr 21 13:17 2012_04_01
-rw-r--r-- 1 root root 488630 Apr 21 13:17 2012_04_02
リンクされた質問の回答に基づいて、次のコードを含むスクリプトがあり、正常に動作します:-
DIR="/tmp/tmp"
for month in $(find "$DIR" -maxdepth 1 -type f | sed 's/.*\/\([0-9]\{4\}_[0-9]\{2\}\).*/\1/' | sort -u); do
echo "Start awk command for files $month"
power=$(awk -F, '{ x += $1 } END { print x/NR }' "$DIR/${month}"_[0-3][0-9])
echo $power
done
以下のコマンドを単独で実行すると、次のようなリストが返されます:-
find /tmp/tmp -maxdepth 1 -type f | sed 's/.*\/\([0-9]\{4\}_[0-9]\{2\}\).*/\1/' | sort -u
2011_05
2011_06
2011_07
2011_08
2011_09
2011_10
2011_11
2011_12
2012_01
2012_02
2012_03
2012_04
find コマンドは、GLOB を使用して一連のファイルを AWK に渡し、バッチとして処理されます。
これを踏まえて、以下のカットコマンドを実行できるようにしたいです
head -1 FirstFile | date -d "`cut -d, -f7`" +%s
tail -1 LastFile | date -d "`cut -d, -f7`" +%s
これらは FIRST および LAST ファイル PER SET に対して実行する必要があります
上記の 2012_03 の場合、2012_03_25 ファイルに対してヘッドを実行する必要があり、2012_03_31 に対してテールを実行する必要があります。これは、これらが 3 月のセットの最初と最後のファイルであるためです。
したがって、基本的には、バッチごとに最初と最後のファイルを取得できる必要があります。
これが十分に明確になっていることを願っています。そうでない場合は、コメントしてください。