create file list: SED inline vs SED standalone, enormous speed difference
Hello to all the community
I've created this one line command, script, to create files lists, that works, though Code:
ls -R1 /rootpathname/ | while read l; do case $l in *:) d=${l%:};; "") d=;; *) echo "$d/$l";; esac; done > /tmp/filelistname.txt Code:
/media/volumename so I've added some sed, but the speed slowed down in a terrible manner, hundreds times slower here it is the code, though... and it works Code:
ls -R1 /media/MAC01/ | while read l; do case $l in *:) d=${l%:};; "") d=;; *) echo $d/$l | sed 's/\/media\/MAC01//';; esac; done > /tmp/MAC01-file-list.txt Code:
ls -R1 /media/MAC01/ | while read l; do case $l in *:) d=${l%:};; "") d=;; *) echo "$d/$l";; esac; done > /tmp/MAC01-file-list.txt Code:
sed 's/\/media\/MAC01//' /tmp/MAC01-file-list.txt > /tmp/MAC01-file-list-cleaned.txt Do any of you have an technical explanation about this enormous speed difference? Have I placed the sed command in a wrong position? Thank you for hinting Cor |
Maybe the command substitution technique could help increasing the speed,
since they write it extracts the stdout of a command, then assigns it to a variable using the = operator. but I don't find any reference that I could understand to apply it to the above "slow" script. |
Seems like a awfully complicated way of producing a file list.
Can't you just use 'find'? Code:
find "/media/MAC01/" -type f -printf "%P\n" | sort > filelist.txt The reason your code is so slow is because you placed the call to sed within the body of the loop, so you're asking it to start 400,000 instances of sed, one after the other. |
thank you GazL
it works and it is fast searching I've also found this command Code:
find . > filelist.txt to only count the files in a tree , the output could be piped to wc, like this find . | wc -l Cor |
Please remember to mark as SOLVED once you have a solution
|
All times are GMT -5. The time now is 08:16 PM. |