異なるフォルダーに同じ名前の .gz ファイルがいくつかあります。したがって、これらすべての .gz ファイルを解凍し、すべての出力ファイルを 1 つのファイルに結合したいと考えています。
1527 次
3 に答える
1
find . -name "xyz.gz"|xargs zcat >output_file
于 2012-10-01T09:06:17.960 に答える
1
ファイルの名前が事前にわからない場合は、次のスクリプトが役立つことがあります。として実行する必要がありますmy-script.sh /path/to/search/for/duplicate/names /target/dir/to/create/combined/files
。指定されたパスで複数回出現するすべてのファイル名を検索し、それらのコンテンツをターゲット ディレクトリ内の 1 つのファイルに結合します。
#! /bin/bash
path=$1
target=$2
[[ -d $path ]] || { echo 'Path not found' ; exit 1 ; }
[[ -d $target ]] || { echo 'Target not found' ; exit 1; }
find "$path" -name '*.gz' | \
rev | cut -f1 -d/ | rev | \ # remove the paths
sort | uniq -c | \ # count numbers of occurrences
grep -v '^ *1 ' | \ # skip the unique files
while read _num file ; do # process the files in a loop
find -name "$file" -exec zcat {} \; | \ # find the files with the given name and output their content
gzip > "$target/${file##*/}" # gzip the target file
done
于 2012-10-01T09:27:36.253 に答える
0
find some/dir -name foo.gz -exec zcat {} \; > output.file
于 2012-10-01T07:37:09.967 に答える