1

My problem statement is I am having the whole hdfs path that may or may not have part* at the end on this.

Like: /user/root/daily_file/part* or /user/root/daily_file/p*

I will have the above string in one variable in my shell script.

But I want to remove the last part* or p* what ever we have in between "/" and "*".

My code snippet is:

hdfs_path="/user/root/daily_file/part*"
hdfs dfs -test -e $hdfs_path
    rc=$?
    if [ "$rc" -eq "0" ]
    then
    echo -e  "path exist !!! \n"
    if

Due to path -

Jahid
  • 21,542
  • 10
  • 90
  • 108
Indrajeet Gour
  • 4,020
  • 5
  • 43
  • 70
  • What is the purpose of this program? I mean, what do you want to do next? Perhaps what you seek is already there in the HDFS API (https://hadoop.apache.org/docs/current/api/org/apache/hadoop/fs/FileSystem.html). I am not sure that I understood what the problem is... Also check that the code snippet is complete. It ends with an `if`... – vefthym Jun 03 '15 at 09:33

1 Answers1

1

I think you want this:

var="/user/root/daily_file/part*"
echo "${var%/*}"

If you want to get exactly /user/root/daily_file/, then: newvar="${var%/*}/"

Jahid
  • 21,542
  • 10
  • 90
  • 108