pipe to uniq from a variable not showing the desired output
0
votes
2
answers
57
views
I have a pipeline using array jobs and need to change the number of inputs for some steps. I thought about testing
uniq
since the only part changing in my folders are the last four characters (the *hap* part in the example). So, all my paths look something like:
/mnt/nvme/user/something1/hap1
/mnt/nvme/user/something1/hap2
/mnt/nvme/user/something2/hap1
/mnt/nvme/user/something2/hap2
and what I'm doing is the following:
DIR=( "/mnt/nvme/ungaro/something1/hap1" "/mnt/nvme/ungaro/something1/hap2" "/mnt/nvme/ungaro/something2/hap1" "/mnt/nvme/ungaro/something2/hap2" )
for dir in "${DIR[@]}"; do echo $dir | sed 's#/hap[0-9]##' | uniq; done
But the resulting output always displays all the elements in the variable without collapsing the duplicate rows after removing the *hap* part of each one of them.
Probably I'm missing something, could it be that the for
forces to print all lines anyway. If so, is there a way to attained the desired result in a single line command?
Asked by Matteo
(209 rep)
Feb 10, 2025, 04:25 PM
Last activity: Feb 10, 2025, 05:16 PM
Last activity: Feb 10, 2025, 05:16 PM