简体   繁体   English

使用bash脚本创建gzip文件

[英]Creating a gzip file using bash script

I have a bash script that produces a bunch of files. 我有一个bash脚本,可以生成一堆文件。 However I wanted my files to be gzip. 但是我希望我的文件是gzip。 The way I've written my script, it produces files with *.gz extension. 我编写脚本的方式会产生带有* .gz扩展名的文件。 But, when I check whether it's gzip or not using the command 但是,当我使用命令检查是否为gzip时

gzip -l hard_0.msOut.gz 

it says gzip: hard_0.msOut.gz: not in gzip format 它说gzip:hard_0.msOut.gz:不是gzip格式

My bash script is: 我的bash脚本是:


#!/bin/bash

#generating training data

i_hard=0
i_soft=0
i_neutral=0

for entry in /home/noor/popGen/sweeps/slim_script/singlePop/*
do
    if [[ $entry == *"hard"* ]]; then
        echo "It's there!"
        /home/noor/popGen/build/./slim $entry > /home/noor/popGen/sweeps/msOut/singlePop/hard_$i_hard.msOut.gz
        i_hard=$((i_hard+1))
    fi

    if [[ $entry == *"soft"* ]]; then
        echo "It's there!"
        /home/noor/popGen/build/./slim $entry > /home/noor/popGen/sweeps/msOut/singlePop/soft_$i_soft.msOut.gz
        i_soft=$((i_soft+1))
    fi
    if [[ $entry == *"neutral"* ]]; then
        echo "It's there!"
        /home/noor/popGen/build/./slim $entry > /home/noor/popGen/sweeps/msOut/singlePop/neutral_$i_neutral.msOut.gz
        i_neutral=$((i_neutral+1))
    fi

done

Can someone tell me how can produce gzip files using the bash script that I've made. 有人可以告诉我如何使用我制作的bash脚本生成gzip文件。

You're outputting the values to a file called something.gz, but that doesn't mean it's gzipped. 您正在将这些值输出到一个名为something.gz的文件中,但这并不意味着它已压缩。 That just means that you've chosen to have a file extension of .gz. 这仅表示您选择的文件扩展名为.gz。

To gzip the output, add the following for example: 要gzip输出,请添加以下示例:

echo "compress me" | gzip -c > file.gz

The above will take the output of the echo and pipe it to gzip (-c will send to stdout) and redirect stdout to a file named file.gz 上面的代码将获取echo的输出并将其通过管道传输到gzip(-c将发送到stdout)并将stdout重定向到名为file.gz的文件

Your complete code: 您的完整代码:

#!/bin/bash

#generating training data

i_hard=0
i_soft=0
i_neutral=0

for entry in /home/noor/popGen/sweeps/slim_script/singlePop/*
do
    if [[ $entry == *"hard"* ]]; then
        echo "It's there!"
        /home/noor/popGen/build/./slim $entry | gzip -c > /home/noor/popGen/sweeps/msOut/singlePop/hard_$i_hard.msOut.gz
        i_hard=$((i_hard+1))
    fi

    if [[ $entry == *"soft"* ]]; then
        echo "It's there!"
        /home/noor/popGen/build/./slim $entry | gzip -c > /home/noor/popGen/sweeps/msOut/singlePop/soft_$i_soft.msOut.gz
        i_soft=$((i_soft+1))
    fi
    if [[ $entry == *"neutral"* ]]; then
        echo "It's there!"
        /home/noor/popGen/build/./slim $entry | gzip -c > /home/noor/popGen/sweeps/msOut/singlePop/neutral_$i_neutral.msOut.gz
        i_neutral=$((i_neutral+1))
    fi

done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM