2012-10-01 109 views

回答

0
find some/dir -name foo.gz -exec zcat {} \; > output.file 
1
find . -name "xyz.gz"|xargs zcat >output_file 
1

如果你不預先知道文件的名稱,您可能會發現下面的腳本有幫助的。你應該運行它作爲my-script.sh /path/to/search/for/duplicate/names /target/dir/to/create/combined/files。它會查找給定路徑中多次出現的所有文件名,並將其內容組合到目標目錄中的單個文件中。

#! /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 
相關問題