ubuntu-users@lists.ubuntu.com
[Top] [All Lists]

Re: OT: Bash script help needed

Subject: Re: OT: Bash script help needed
From: Nils Kassube
Date: Thu, 20 Dec 2007 15:25:02 +0100
Craig Puchta wrote:
> Here is what I have and want to do.
> In one directory I have tens of thousands of .txt files named as such:
>
> rdb-001-001.txt
> rdb-001-002.txt
> rdg-002-001.txt
> rdg-002-002.txt
> and so on.
>
> What I want to do (and not manually, as I haven't even put a dent in it
> yet) is:
>
> mkdir rdb-001
> mv rdb-001-* rdb-001
> mkdir rbg-002
> mv rbg-002-* rbg-002

Depending on the file name pattern, this may be what you are looking for:

find -maxdepth 1 -type f -name \*[0-9][0-9][0-9].txt | while read f;do
  d=${f#./}
  d=${d%-???.txt}
  echo "mkdir -p $d"
  echo "mv $f $d"
done

This only displays what it would do. If that's OK, replace the lines

  echo "mkdir -p $d"
  echo "mv $f $d"

with

  mkdir -p $d
  mv $f $d



Nils

-- 
ubuntu-users mailing list
ubuntu-users@xxxxxxxxxxxxxxxx
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

<Prev in Thread] Current Thread [Next in Thread>