At 9/14/2005 05:35 +0000, vick Julius wrote:
I want to rename files with the new names from a text file, names.txt:
I want to renmae all files (in *.doc) with the new names read from
names.txt file.
The problem is the names in the file names.txt have spaces...
I created a small test environment:
$ ls -1
a.doc
b.doc
c.doc
names.txt
$ cat names.txt
first file
second file
third file
$ for pair in $(ls -1 *.doc |paste -d: - names.txt |tr ' ' '~')
> do cp -v "${pair%%:*}" "$(echo ${pair#*:} |tr '~' ' ')"
> done
`a.doc' -> `first file'
`b.doc' -> `second file'
`c.doc' -> `third file'
$ ls -1
a.doc
b.doc
c.doc
first file
names.txt
second file
third file
$
Change "cp" to "mv" to rename the files. Note that I've assumed none
of the files have ":" or "~"; if this isn't true, substitute other characters.
--
Jeff Woods <kazrak+kernel@xxxxxxxxxxx>
-
: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html