Sponsored Content
Top Forums Shell Programming and Scripting Problem renaming files using variables Post 302782145 by hubleo on Monday 18th of March 2013 10:31:20 AM
Old 03-18-2013
Problem renaming files using variables

Hi, I have the following problem:

I have a list of files:
Code:
1.txt
2.txt
3.txt
4.txt

Then I have a list of variable names inside variable.txt:
Code:
A
B
C
D

I'd like to rename 1.txt, 2.txt etc using the variables from variable.txt
Code:
 
A.txt (Contains info from 1.txt)
B.txt (Contains info from 2.txt)
C.txt (Contains info from 3.txt)
D.txt (Contains info from 4.txt)

I've tried using this, but it doesn't work
Code:
END=4
for ((i=1;i<=END;i++)); do for j in $(cat variable.txt); do mv "$i".txt "$j".txt; done; done

When doing this, I get a list of files
Code:
 
A.txt  > (Contains info from 4.txt)
B.txt  > (Contains info from 4.txt)
C.txt  > (Contains info from 4.txt)
D.txt  > (Contains info from 4.txt)

but want

A.txt (Contains info from 1.txt)
B.txt (Contains info from 2.txt)
C.txt (Contains info from 3.txt)
D.txt (Contains info from 4.txt)

Something is going wrong with the loop and can't work out why it's doing this. I'm trying to learn scripting/loops and any help would be appreciated. Many thanks
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

advanced file renaming problem

I know this is probably a question for the newbie forum, where it is also posted, but I thought maybe some of you pros might like to help me out anyway. Here is my problem: I have to rename a batch of files that look like: 2001_0001.asc 2001_0002.asc . 2001_0548.asc 2002_0184.asc . .... (0 Replies)
Discussion started by: sea krait
0 Replies

2. UNIX for Advanced & Expert Users

problem with renaming files

Hi, I need to rename all the .txt files present in current directory to .dat files respectively in UNIX. for example: $ ls aaa.txt bbb.txt ccc.txt I need to change them to $ ls aaa.dat bbb.dat ccc.dat Is there any UNIX command to do this in one go? ... (3 Replies)
Discussion started by: Johny001
3 Replies

3. UNIX for Advanced & Expert Users

Renaming Multiple Files that have variables in the name

I am trying to rename multiple files from lower case to upper case, but then I need to change the word SHIP to Ship and CSV to csv. This is a sample of the input file name input_file_ship_1234_20110106.csv I need this to look like this INPUT_FILE_Ship_1234_20110106.csv this is the result when I... (3 Replies)
Discussion started by: cventura
3 Replies

4. Shell Programming and Scripting

renaming files or adding a name in the beginning of all files in a folder

Hi All I have a folder that contains hundreds of file with a names 3.msa 4.msa 21.msa 6.msa 345.msa 456.msa 98.msa ... ... ... I need rename each of this file by adding "core_" in the begiining of each file such as core_3.msa core_4.msa core_21.msa (4 Replies)
Discussion started by: Lucky Ali
4 Replies

5. Shell Programming and Scripting

Problem with renaming and saving

Hello mates, I am quite new to script programming and I am facing an uphill task to rename files in one folder. I have gone through similar posts but most of them deal with renaming files by changing the file extensions. Problem : I have a folder which contains files like... (5 Replies)
Discussion started by: chirag.joshi
5 Replies

6. Shell Programming and Scripting

File renaming problem

Can someone tell me how can i remove the RPCFTP word from RPCFTPfilelist.csv file ? (4 Replies)
Discussion started by: JSKOBS
4 Replies

7. Shell Programming and Scripting

Loop renaming files w/ a count problem

:wall: Hello there, basically in my program where im stuck at is when it comes to rename the files in a loop. - the program counts the number of files w a given name (works!) - and then if the number of files is greater or equal to the MAX_VERSIONS (numbers of files allowed w the... (1 Reply)
Discussion started by: thurft
1 Replies

8. UNIX for Advanced & Expert Users

Problem with renaming files

I have about 1000 files containing the character * in the name. I need to find these files and replace the * with a -. I am working with HP UX v11. I am using the following command find . -type f -name '*\**' -exec bash -c 'f="$1"; mv "$f" "${f//\*/-}"' - '{}' \ People tell me it works for... (4 Replies)
Discussion started by: MikeDavid
4 Replies

9. Shell Programming and Scripting

Renaming multiple files in sftp server in a get files script

Hi, In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this? I am using #!/bin/ksh For eg: sftp user@host <<EOF cd /path get *.txt rename *.txt *.txt.done ... (7 Replies)
Discussion started by: jhilmil
7 Replies

10. Shell Programming and Scripting

Problem renaming files on Solaris 10 server

Good day all. I'm trying to rename some files in my home directory with some bizarre results. Basically I need to change the IP address in the filename to the hostname which I ggrep from within the file: -rw-r--r-- 1 bh694n nrc 5095 May 2 20:03 alarms_999.189.161.146.log... (2 Replies)
Discussion started by: BRH
2 Replies
XCLIP-COPYFILE(1)					      General Commands Manual						 XCLIP-COPYFILE(1)

NAME
xclip-copyfile, xclip-cutfile, xclip-pastefile - copy and move files via the X clipboard SYNOPSIS
xclip-copyfile [-p] FILES... xclip-cutfile [-p] FILES... xclip-pastefile DESCRIPTION
xclip-copyfile copies files into the X clipboard, recursing into directories. xclip-cutfile copies the files, but also deletes them afterwards. -p preserve path formation xclip-pastefile pastes the files out of the clipboard EXAMPLES
Copying a file to a remote host [maggie.lkpg.cendio.se ~]$ echo "A file created on ${HOSTNAME}" > file1 [maggie.lkpg.cendio.se ~]$ xclip-copyfile file1 [sofie.homeip.net ~/doc]$ xclip-pastefile file1 [sofie.homeip.net ~/doc]$ cat file1 A file created on maggie.lkpg.cendio.se Copying an entire tree structure [sofie.homeip.net ~]$ xclip-copyfile doc [maggie.lkpg.cendio.se ~/tmp]$ xclip-pastefile doc/ doc/letter-mom-april.txt doc/file1 doc/letter-dad-march.txt Copying files with preserved path information [maggie.lkpg.cendio.se ~]$ xclip-copyfile -p /etc/sysconfig/grub tar: Removing leading `/' from member names [sofie.homeip.net ~/tmp]$ xclip-pastefile etc/sysconfig/grub [sofie.homeip.net ~/tmp]$ ls etc/sysconfig/grub etc/sysconfig/grub Moving files [sofie.homeip.net ~]$ ls letter-brother-may.txt letter-brother-may.txt [sofie.homeip.net ~]$ xclip-cutfile letter-brother-may.txt [sofie.homeip.net ~]$ ls letter-brother-may.txt ls: cannot access letter-brother-may.txt: No such file or directory [sofie.homeip.net ~]$ cd doc [sofie.homeip.net ~/doc]$ xclip-pastefile letter-brother-may.txt AUTHORS
This manual page was written by Maximilian Gass <mxey@cloudconnected.org> for the Debian project. It may be used for everything else, of course. XCLIP-COPYFILE(1)
All times are GMT -4. The time now is 02:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy