Sponsored Content
Top Forums Shell Programming and Scripting File renaming from list of names contained in another file Post 302432865 by netfreighter on Sunday 27th of June 2010 05:48:45 PM
Old 06-27-2010
File renaming from list of names contained in another file

I have to rename a large number of files so that the name of each file corresponds to a code number that is given side by side in a list (textfile).
The list contains in column A the filename of the actual files to be renamed and in column B the name (a client code, 9 digits) that has to be assigned to the file.

Listfile:
file-abcd.pdf #to be renamed [tab] 123456789 #the new filename
file-abce.pdf #to be renamed [tab] 809809231 #the new filename
a.s.o

Desired outcome:
file-abcd.pdf --> file.123456789.pdf
file-abce.pdf --> file.809809231.pdf
a.s.o

It's to say "for F in each actual file in files/ named like this on the left, re-name it to the name to the right and keep the old extension... But bash did not understand this phrase Smilie)
The names to be given are stored in a file but the files to name are actual files, so just no idea how to tackle this and where to even start.

So far all the scripting I could do and understand in bash was loops to rename just an extension to a file, or to add an extra suffix. Beginner... sigh... But there has to be a way to do it in Linux, there usually is.
Thanks in advance for your help!
 

10 More Discussions You Might Find Interesting

1. AIX

find for specific content in file in the directory and list only file names

Hi, I am trying to find the content of file using grep and find command and list only the file names but i am getting entire file list of files in the directory find . -exec grep "test" {} \; -ls Can anyone of you correct this (2 Replies)
Discussion started by: madhu_Jagarapu
2 Replies

2. Shell Programming and Scripting

Renaming file names in a shell script

I want to write a shell script that will rename all the file names to today's date attached to it.. so for example i have a file names like file1.sales.20081201.txt.c zbrs.salestxtn.20091101.txt.inn then it will rename both the files with todays date to it so the file names get changed... (1 Reply)
Discussion started by: rudoraj
1 Replies

3. Shell Programming and Scripting

Renaming file names

I have 7 files with 7 different names coming into a specified folder on weekly basis, i need to pick a file one after another and load into oracle table using sql loader. I am using ksh to do this. So in the process if the file has error records and if sql loader fails to load into oracle tables,... (2 Replies)
Discussion started by: vpv0002
2 Replies

4. Shell Programming and Scripting

List of file names

I have the following list of file names stored in $fnames, so that if I do foreach f ($fnames) echo "$f" end I will get n02-z30-sr65-rgdt0p50-dc0p002-16x12drw-run1 n02-z30-sr65-rgdt0p50-dc0p002-16x12drw-run2 n02-z30-sr65-rgdt0p50-dc0p002-16x12drw-run3... (3 Replies)
Discussion started by: kristinu
3 Replies

5. UNIX for Dummies Questions & Answers

Renaming files in one file from names in other

Hi Guys, I have a small problem of renaming multiple files. For example I have names of a set of files in one directory like K2_34625-34675 K7_988963-988983 K12_773882-7734102 and the other set corresponding to the same is U_P_321_9_3_11.ab1 U_P_322_9_3_11.ab1 U_P_323_9_3_11.ab1 Now... (23 Replies)
Discussion started by: pawannoel
23 Replies

6. Shell Programming and Scripting

Shell Scripts (Renaming file names with sequential numbers)

Hi there, Firstly, I have no experience with shell scripts so would really appreciate some help. I have the following shell script that is causing some problems: moveit() { && set -x if then DOUBLE_DELIVERY=$(grep... (6 Replies)
Discussion started by: thebeno
6 Replies

7. Shell Programming and Scripting

Renaming File Names in a folder/Dir

Hi Team, I'm new to Unix shell scripting . I've the following requirement A folder contains the list of files with the following format ab.name.11.first ab.name.12.second ab.name.13.third ---------- I have to rename the above file to like below ... (6 Replies)
Discussion started by: smile689
6 Replies

8. Shell Programming and Scripting

List the file names available on FTP server before selecting the required file

Below is my script code.which shows the environment name and then fetch the file from the ftp server but I am facing one issue.The script should be run in both way.We can pass the arguments with script and select the environment name then file name.Here the issue is I am not able to list the files... (1 Reply)
Discussion started by: anuragpgtgerman
1 Replies

9. Shell Programming and Scripting

While loop a file containing list of file names until the files are found?

Hi, I have a control file which will contain all filenames(300) files. Loop through all the file names in the control files and check the existence of this file in another directory(same server). I need to infinitely(2 hrs) run this while loop until all the files are found. Once a file is found,... (5 Replies)
Discussion started by: laknar
5 Replies

10. UNIX for Beginners Questions & Answers

Renaming the file names in a directory

Hi, I have about 60 files in a directory and need to rename those files. For example the file names are i_can_phone_yymmdd.txt (where yymmdd is the date. i.e 170420 etc) i_usa_phone_1_yymmdd.txt i_eng_phone_4_yymmdd.txt The new file names should be phone.txt phone_1.txt phone_4.txt I am... (4 Replies)
Discussion started by: naveed
4 Replies
BTAG(1) 							    btag Manual 							   BTAG(1)

NAME
btag - A command line based multimedia tagger SYNOPSIS
btag [options] path1 [path2] [path3] ... DESCRIPTION
btag is a TagLib-based command line multimedia tag editor that attempts to automate the process of tagging a lot of files at once. It uses the tags found in the supplied files as well as interactive user input to determine new values for the tags. It can also optionally rename files and directories based on those new values. You can supply paths to files or directories to btag. Directories are recursively traversed and all files found are tagged. Directories are also handled differently in the sense that btag will attempt to keep information about the previously tagged files to provide sane defaults for all other files in the same parent directory. Only files with file extensions supported by TagLib are considered. OPTIONS
-D/--dry-run Don't do anything, just show what would have been done (dry run mode) -d/--dir-rename-format format Use format to rename the directories where the multimedia files were found -i/--input-filter filter Use filter as the input filter -f/--filter filter Use filter as both the input and the output filter -h/--help Display usage information and exit -n/--renaming-filter filter Use filter as the renaming filter -o/--output-filter filter Use filter as the input filter -r/--file-rename-format format Use format to rename the multimedia files -t/--title-locale locale Use locale for proper (although lax) locale-specific title casing INPUT AND OUTPUT FILTERS
btag supports input and output filters that are applied to the text fields (artist, album and song title). Those filters can protect against basic mistakes such as duplicate whitespace. Input filters are used on the tags as they are loaded from the multimedia files. This filtered information is used to provide suggestions to the user when the interactive tagger requests information for those text fields. If an output filter is configured, the user input is then filtered, and if the filtered text does not match the user input, the user is asked for confirmation. In most cases, the input filter should match the output filter (which is why the -f option is handy). You may choose to specify only an input filter, in which case the user input is not filtered. If you don't specify an input filter, though, the default input filter will be used. The currently available filters are: basic Provides basic filtering by removing duplicate or trailing whitespace, is the default input filter and the base for all other filters first_upper The first character in the field is uppercased, while all others are lowercased lower All characters are lowercased title The first character of each word is uppercased (with exceptions), while all others are lowercased upper All characters are uppercased The title capitalization algorithm will follow locale-specific context-insensitive rules depending on the value of the -t parameter. Note that strict title capitalization rules often depend on the context in which the words are used, the precise analysis of which is much beyond the scope of btag. The currently supported title locale specifications are: en English (default) es Spanish RENAMING FORMATS
If a format is specified with the -r option, the tagged multimedia files are renamed accordingly. Likewise, if the -d option is used, the directory in which multimedia files were tagged is renamed according to the specified format. The specified format is converted to a file or directory name using the following substitutions: %artist Artist name %album Album name %year Year of release %track Track number (only replaced by the -r option) %title Song title (only replaced by the -r option) Renaming happens after the tags are written, and it's relative to btag's working directory. For directory renaming, the last known artist, album and year information is used. Only directories that contain files that were tagged by btag are renamed. btag does not prevent you from overwriting existing files using the formats described here. RENAMING FILTERS
Renaming filters are used to ensure that the file and directory names generated using the renaming formats (if specified) are valid (safe) in the context of the current file system. The following renaming filters are currently available: conservative Conservative character replacements are performed, recommended for FAT32 file systems unix Generates file and directory names that should be valid in an Unix environment (default) EXAMPLE
Using title casing with English rules and sensible renaming formats generating FAT32-safe file and directory names: $ btag --file-rename-format '%track. %title' --dir-rename-format '%album (%year)' --filter title --title-locale en --renaming-format conservative /path/to/myalbum Using an input filter only: $ btag --input-filter lower /path/to/myalbum btag 2011-06-04 BTAG(1)
All times are GMT -4. The time now is 01:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy