I have a script I've used for many years for building a list to some directories, with the following lines:
##Find all scenarios for this sector number
find /gsgt/source/scenarios/AT_* -name ${current}"*" -type d | \
awk -F"/" '{print $NF}' > Sector_${current}_list.txt
find /gsgt/source/scenarios/AT_* -name "3T${current}*" -type d | \
awk -F"/" '{print $NF}' >> Sector_${current}_list.txt
find /gsgt/source/scenarios/AT_* -name "4T${current}*" -type d | \
awk -F"/" '{print $NF}' >> Sector_${current}_list.txt
find /gsgt/source/scenarios/AT_* -name "Sector_${current}*" -type d | \
awk -F"/" '{print $NF}' >> Sector_${current}_list.txt`
This gives me a list of only the directory names. The commands take a split second to complete. Recently, we've found a need to start with full path statements in a similar script. I rewrote the section without the pipe into awk as follows:
##Find all scenarios for this sector number, put them into list
find /gsgt/source/scenarios/AT_* -name ${current}"*" -type d \
> Sector_${current}_list.txt
find /gsgt/source/scenarios/AT_* -name "3T${current}*" -type d \
>> Sector_${current}_list.txt
find /gsgt/source/scenarios/AT_* -name "4T${current}*" -type d \
>> Sector_${current}_list.txt
find /gsgt/source/scenarios/AT_* -name "Sector_${current}*" -type d \
>> Sector_${current}_list.txt
This gives me the same list with full path statements, and works, but it takes *nearly a minute* to complete. It's searching the same tree structure, with the same variable input.
Why is the second one, which seems "simpler", so much slower?
Asked by atc_ceedee
(113 rep)
Jul 20, 2024, 06:15 PM
Last activity: Nov 14, 2024, 07:09 PM
Last activity: Nov 14, 2024, 07:09 PM