Re: shell script question:How 2 assign several fields from a file to a variable? | |
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] | |
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
[Site Home] [Linux Newbie] [Audio] [Hams] [Kernel Newbies] [Memory] [Util Linux NG] [Security] [Netfilter] [Bugtraq] [Writing Drivers] [Photo] [Yosemite Photos] [Yosemite News] [MIPS Linux] [ARM Linux] [Linux Security] [Linux RAID] [Samba] [Video 4 Linux] [Git] [Linux Resources] [Fedora Users]
![]() |