Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7998745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:18:01+00:00 2026-06-04T15:18:01+00:00

I have a bash script with the following lines for file in $diff_file_list do

  • 0

I have a bash script with the following lines

for file in $diff_file_list
    do

        # replace any ? with $current_date and replace any % with $file
        formatted_output_filename=$(echo $output_filename | sed "s|?|$current_date|g" | sed "s|%|_$file|g")
        $pig_bin_dir/pig -param preceding=$hdfs_hadoop_pre_dir/$file -param current=$hdfs_hadoop_cur_dir/$file -param output_added=$hdfs_hadoop_delta_dir/${file}_added -param output_removed=$hdfs_hadoop_delta_dir/${file}_removed -param delimiter=$delimiter diff.pig
        [ $? -ne 0 ] && die "diff of data between $previous_date and $current_date using pig failed. exiting `basename $0` script"
        $hadoop_bin_dir/hadoop dfs -cat $hdfs_hadoop_delta_dir/${file}_added/* | gzip > $file_output_dir/${formatted_output_filename}_added.gz
        $hadoop_bin_dir/hadoop dfs -cat $hdfs_hadoop_delta_dir/${file}_removed/* | gzip > $file_output_dir/${formatted_output_filename}_removed.gz
        [ $? -ne 0 ] && die "there was a problem gzipping ${formatted_output_filename}. exiting `basename $0` script"
        [ $post_diff_script ] && ./$post_diff_script $source $previous_date $current_date

    done

I only want it to create the _removed.gz and _added.gz files when the file is not empty.
I’ve tried to do this below but there is something wrong with my script?

    for file in $diff_file_list
    do

        # replace any ? with $current_date and replace any % with $file
        formatted_output_filename=$(echo $output_filename | sed "s|?|$current_date|g" | sed "s|%|_$file|g")
        $pig_bin_dir/pig -param preceding=$hdfs_hadoop_pre_dir/$file -param current=$hdfs_hadoop_cur_dir/$file -param output_added=$hdfs_hadoop_delta_dir/${file}_added -param output_removed=$hdfs_hadoop_delta_dir/${file}_removed -param delimiter=$delimiter diff.pig
        [ $? -ne 0 ] && die "diff of data between $previous_date and $current_date using pig failed. exiting `basename $0` script"
        if [[ -s $hdfs_hadoop_delta_dir/${file}_added/* ]] ; then
        echo "$hdfs_hadoop_delta_dir/${file}_added/* has data."
        $hadoop_bin_dir/hadoop dfs -cat $hdfs_hadoop_delta_dir/${file}_added/* | gzip > $file_output_dir/${formatted_output_filename}_added.gz
        $hadoop_bin_dir/hadoop dfs -cat $hdfs_hadoop_delta_dir/${file}_removed/* | gzip > $file_output_dir/${formatted_output_filename}_removed.gz
        else
        echo "$hdfs_hadoop_delta_dir/${file}_added/*is empty."
        fi ;
        [ $? -ne 0 ] && die "there was a problem gzipping ${formatted_output_filename}. exiting `basename $0` script"
        [ $post_diff_script ] && ./$post_diff_script $source $previous_date $current_date

    done
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:18:03+00:00Added an answer on June 4, 2026 at 3:18 pm
    if [[ -s file ]]
    then
        do_file_creation
    fi
    

    or

    for f in dir/*
    do
        if [[ -s $f ]]
        then
            do_file_creation
        fi
    done
    

    Use lower case or mixed case variable names.

    Use if instead of [[ ]] &&

    Use indentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following bash script: #DIR is something like: /home/foo/foobar/test/ without any whitespace
I have a shell script file (run.sh) that contains the following: #!/bin/bash %JAVA_HOME%/bin/java -jar
I need to add 3 lines into a file via a bash script; sed
I have a bash script, replace.sh with the following contents: ack-grep -a -l -i
I have already following bash script. It count lines in *.cpp only. How i
I have the following sed -e 's/<em\:update.*//g' install.rdf > install.rdf in a bash script,
Let’s say I have the following Bash script: while read SCRIPT_SOURCE_LINE; do echo $SCRIPT_SOURCE_LINE
I have a following bash script: 1 #!/bin/bash 2 query='query= SELECT * WHERE {
I have a bash script that sources contents from another file. The contents of
I have a bash-script (let's call it /usr/bin/bosh ) using the following she-bang line:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.