Hdfs count command tweak I am using below command to assign a value, Is there a alternative way to get by tweaking the code
var=hdfs dfs -ls /hdfs_path/ | grep col=2020_03 | awk -F' ' '{system(&quot;hdfs dfs -count &quot;$8)}' | awk -F' ' '{if ($3 != 0) print $4}' | awk -F'=' '{print $2}'|sort -nr | uniq | head -1

Basically i am need to find the latest month value that holds data in hdfs directory. For eg
hdfs_path/col=2020_03_21/data.part - this has no data
    hdfs_path/col=2020_03_20/data.part - this has data
    hdfs_path/col=2020_03_19/data.part - this has data

hence output should be val = 2020_03_20
Just some comments on the last part of the command.
Since you don't use any of the extra features of uniq, you can drop replace
sort -nr | uniq
with
sort -nr -u

I don't see a reason to sort in reverse, and then take the first line with head -1, when you could instead use tail -1.
sort -nu | tail -1

While outputting duplicated lines to tail might take some time if there is a lot of duplication, since you only actually want the final line, you can probably drop the -u flag in sort. If you wanted the most recent 3 dates, you'd need to add it back in.