Randall R Schulz skrev:
Anders,

On Monday 12 March 2007 08:42, Anders Norrbring wrote:
I'm looking for shell help..
I have a directory with thousands of files named in the format
'file_XX_YY.txt' where XX would represent 2 characters and/or digits
and YY is numbers from 00 to 99.

What I want to do is to move all files named 'file_XX*' to
directories named as 'file_XX'.

Generate the list of directories:

dirNames=( $(ls |sed -rn 's/file_(..)_[0-9][0-9].txt/file_\1/p' |sort -u )
)

Iterate over those directory names, creating the directory if necessary and then moving all the corresponding files into that directory:

for dirName in "[EMAIL PROTECTED]"; do

    mkdir -p "$dirName"

    for fileName in "$dirName"_[0-9][0-9].txt; do
        mv "$fileName" "$dirName"
    done

done


Thanks Randall, I bet you didn't even think about it either.. :) I really suck on shells.

Any suggestions for a command line or script doing just that?
--

Anders Norrbring
Norrbring Consulting

What sort of consulting do you do?

Mostly hardware and networks, I'm specialized in network design and security.

Anders
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to