Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2014
    Posts
    5

    Unanswered: Binary Operator Expected Error

    Hi,I have a shell script to concatenate multiple files which has the file names starting with file_data* (Let's say file names as file_dataa.csv,file_datab.csv,file_datac.csv) into one big file.But it's giving the error as Binary Operator Expected error.
    Below is the script i am using

    if [ -f $Working_dir\file_data*.csv ];
    then
    echo "Concatenating multiple files with single file in csv format....."
    cat $Working_dir\file_data*.csv > Output.csv
    echo "Concatenated successfully "
    else
    echo "file_data*.csv file not found for processing"
    fi

    Its giving me at this line cat $Working_dir\file_data*.csv > Output.csv saying file_dataa Binary Operator Expected.
    Can anyone please help on this.

    Thanks,

  2. #2
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Unix uses / not \ to separate directory names.

  3. #3
    Join Date
    Nov 2014
    Posts
    5
    So you are saying if i use / instead of \ the error will be resolved?

  4. #4
    Join Date
    Nov 2014
    Posts
    5
    I tried with the changes but i see the same error

    if [ -f $Working_dir/file_data*.csv ];
    then
    echo "Concatenating multiple files with single file in csv format....."
    cat $Working_dir/file_data*.csv > Output.csv--->line 05
    echo "Concatenated successfully "
    else
    echo "file_data*.csv file not found for processing"
    fi

    It gives the error as line 45: [: /working_die/file_datata.csv: binary operator expected

    Thanks


    Quote Originally Posted by kitaman View Post
    Unix uses / not \ to separate directory names.

  5. #5
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    What shell are you using? I tried several experiments but could not duplicate your error.
    Where is Working_dir defined, and what is its value?

    In a sense, your script is redundant. Rather than test to see if there are files, just concatenate them anyway and see if the output file has any size.
    Code:
    rm Output.csv
    cat $Working_dir/file_data*.csv >Output.csv
    if [ -s Output.csv ]
    then
        echo Output.csv has some records
    else
        echo No records are available to process
    fi

  6. #6
    Join Date
    Dec 2012
    Posts
    43
    The error [... binary operator expected occurs if there is more than one file matching "file_data*.csv"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •