You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by Sheng Guo <en...@gmail.com> on 2012/07/23 11:12:38 UTC

how can I delete a file in pig only after checking if the file exists?

Hi all,

Sorry to bother you guys, I used rm FILE_PATH to delete the file in pig
script, but sometimes if the file does not exist, or I am not sure if it
exists, this statement will give some error when I run it.

So is there any method so that I can delete a file in pig script only after
checking the file exists?

Thanks!

Re: how can I delete a file in pig only after checking if the file exists?

Posted by Thejas Nair <th...@hortonworks.com>.
Use - rmf filename

-Thejas

On 7/23/12 2:12 AM, Sheng Guo wrote:
> Hi all,
>
> Sorry to bother you guys, I used rm FILE_PATH to delete the file in pig
> script, but sometimes if the file does not exist, or I am not sure if it
> exists, this statement will give some error when I run it.
>
> So is there any method so that I can delete a file in pig script only after
> checking the file exists?
>
> Thanks!
>



Re: how can I delete a file in pig only after checking if the file exists?

Posted by Ruslan Al-Fakikh <ru...@jalent.ru>.
hi Sheng,

Try something like
sh bash -c 'if hadoop fs -test -e $LOOKUP_HDFS_TEMP; then echo
Deleting old local file lookup; hadoop fs -rm $LOOKUP_HDFS_TEMP; else
echo Local file lookup does not exist; fi'
You can replace the hdfs operations with local filesystem operations.
The idea is that you do
sh bash -c 'YOUR BASH COMMANDS WITH YOUR EXISTANCE CHECKS'

Ruslan

On Mon, Jul 23, 2012 at 1:12 PM, Sheng Guo <en...@gmail.com> wrote:
> Hi all,
>
> Sorry to bother you guys, I used rm FILE_PATH to delete the file in pig
> script, but sometimes if the file does not exist, or I am not sure if it
> exists, this statement will give some error when I run it.
>
> So is there any method so that I can delete a file in pig script only after
> checking the file exists?
>
> Thanks!



-- 
Best Regards,
Ruslan Al-Fakikh