Sponsored Content
Full Discussion: Rename Multiple Files
Top Forums UNIX for Dummies Questions & Answers Rename Multiple Files Post 302815853 by jim mcnamara on Sunday 2nd of June 2013 09:15:19 AM
Old 06-02-2013
One point - consider NOT having spaces in file names. When using cmd.exe or cygwin they can cause problems later on.

This is how it works for what you describe. I put a # in front of the command that renames files. That line is red. Leave it there until you have run through the script, seen the proposed outcomes. Then remove it. In shell # marks the start of a comment - the shell interpreter ignores the stuff after it.

c:/Users/Ralze34/media/mydirectory is a name I made up. Use the correct one. cygwin uses / instead of \ in file names.

this will not work if your files have spaces in the file names
Code:
cd c:/Users/Ralze34/media/mydirectory  # go to where the files are
count=1                                              # start counting at 1
for filename in *                                  # check every file in the directory
do
if  [ -f $filename ] ; then                       # if it a regular file - not a directory
    episode=$(echo "$filename" | awk -F '_'   '{print $6,"_",$7}' )
    newfilename=$(printf "s01e01_%s"  "$episode") # build new file name
    echo "rename $filename to $newfilename"    # show what we did
    # mv $filename $newfilename                  
fi
done


Last edited by jim mcnamara; 06-02-2013 at 09:05 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Rename multiple files

Hello, I want to rename multiple files at a time and I don't know how to do it. I have various ".mp3" files, like "band name - music name.mp3" and I want to remove the "band name" from all files. Anybody knows how to do it using shell script or sed or even perl? Thanks (7 Replies)
Discussion started by: luiz_fer10
7 Replies

2. Shell Programming and Scripting

rename multiple files

Hi, can anyone have a ksh script to rename multiple files (ie to remove .Z extension of the files) can someone correct this? for i in *.Z do var1 = substr($i, 1,at(".Z",$i)-1) mv $i $var1 done Thanks.. Antony (13 Replies)
Discussion started by: antointoronto
13 Replies

3. Shell Programming and Scripting

now to rename multiple files

I have several hundred files in one directory which I need to move to another directory with the new extension, for example: /bb/data/rptmgr* are in the source directory need to be moved to /bb/data55/rptmgr*.new Is there an efficient way to do it? Thanks -A (4 Replies)
Discussion started by: aoussenko
4 Replies

4. UNIX for Dummies Questions & Answers

How to rename multiple files

Hi all, I have some files like: pickup.0000043200.t001.t001.data pickup.0000043200.t001.t002.data pickup.0000043200.t002.t001.data pickup.0000043200.t002.t002.data pickup.0000043200.t003.t001.data pickup.0000043200.t003.t002.data I need to rename these files to ... (4 Replies)
Discussion started by: a_dor8
4 Replies

5. Shell Programming and Scripting

Rename multiple files

hello: I have multiple files with names like: somestring_y2010m01d01 somestring_y2010m01d02 .......... somestring_y2010m12d31 How... (4 Replies)
Discussion started by: sylcam
4 Replies

6. Shell Programming and Scripting

Rename multiple files

Hi, In my directory I have many files, for e.g. file_123 file_124 file_125 file_126 file_127 Instead of renaming these files one by one, I would like to rename them at a same time using same command... they should appear like 123 124 125 126 127 What command(awk or ls or... (3 Replies)
Discussion started by: juzz4fun
3 Replies

7. Shell Programming and Scripting

How to rename multiple files at one go?

Hi, I have hundreds of files with XXX in their file name and I want to rename all of them with YYY in place of XXX. for ex: $ ls -1 123XXX789 345XXX678 Output $ ls -1 123YYY789 345YYY678 I know we can loop in each file and sed to replace and rename each file but ren *XXX* *YYY*... (4 Replies)
Discussion started by: reddyr
4 Replies

8. Shell Programming and Scripting

Rename a multiple files

I have multiple files in folder which i want to rename. hence I am using the below command in my script by I get an error: export XXX_LOG_DIR="${LOG_DIR}/${XXX_HOST}/xxx/${REPORT_DATE}" mv $XXX_LOG_DIR/*.audit.gz $XXX_LOG_DIR/*.audit.log.gz But I get the below error: mv: target... (5 Replies)
Discussion started by: karan8810
5 Replies

9. Shell Programming and Scripting

SBATCH trinity for multiple files and rename/move the output files

Hey guys, I have wrote the following script to apply a module named "trinity" on my files. (it takes two input files and spit a trinity.fasta as output) #!/bin/bash -l #SBATCH -p node #SBATCH -A <projectID> #SBATCH -n 16 #SBATCH -t 7-00:00:00 #SBATCH --mem=128GB #SBATCH --mail-type=ALL... (1 Reply)
Discussion started by: @man
1 Replies

10. Shell Programming and Scripting

Rename multiple files in one go

OS : Oracle Linux 6.8 shell : bash As shown below, I have multiple files like below (query1-extract_aa, query1-extract_ab, query1-extract_ac, ....) $ ls -l total 235680 -rw-rw-r-- 1 reportusr reportusr 30M May 3 11:25 query1-extract_aa -rw-rw-r-- 1 reportusr reportusr 30M May 3 11:25... (5 Replies)
Discussion started by: kraljic
5 Replies
FOOMATIC-RIP(1) 					      General Commands Manual						   FOOMATIC-RIP(1)

NAME
foomatic-rip - Universal print filter/RIP wrapper SYNOPSIS
General Options: foomatic-rip [-v] [-q] <spooler-specific options> Spooler-less printing/CPS (older versions) filter: foomatic-rip [-P <printer> | --ppd <ppdfile> ] [-J <jobtitle> ] [-o <option>=<value> [...]] [<files>] CUPS filter: foomatic-rip <jobid> <user> <jobtitle> <numcopies> <options> [<file>] LPRng filter: foomatic-rip --lprng [-J<jobtitle>][-Z<option>=<value>[,<option>=<value>[, ...]] <ppdfile> foomatic-rip [-J<jobtitle>][-Z<option>=<value>[,<option>=<value>[, ...]] (printcap :pdd=<ppdfile>) foomatic-rip --ppd <ppdfile>[-J<jobtitle>] [-Z<option>=<value>[,<option>=<value>[, ...]] LPD/GNUlpr filter: foomatic-rip [-w <number>] [-l <number>] [-x <number>] [-y <number>] [-i <number>] [-c] [-n <string>] [-h <string>] [-j|-J <jobti- tle>|<options>] <ppdfile> PPR RIP: foomatic-rip [<option>=<value> [...]] PPR interface: foomatic-rip <queue> <destaddress> <options> <jobbreak> <feedback> <codes> <jobname> <routing> <for> <filetype> [<file>] PDQ driver file generation: foomatic-rip [--ppd <ppdfile>] [-o <option>=<value> [...]] --genpdq|--appendpdq|--genrawpdq|--appendrawpdq PDQ filter: foomatic-rip --pdq --ppd <ppdfile>] [-o <option>=<value> [...]] <file> CPS (newer versions) filter: foomatic-rip --cps -P <printer> [-J <jobtitle>] [-o <option>=<value> [...]] [<files>] DESCRIPTION
foomatic-rip is a universal print filter which works with every known free software printer spooler. It has the following features: It translates PostScript and PDF (and also other file formats) from standard input to the printer's native language (usually put to stan- dard output). The translation is done with an external renderer, usually Ghostscript (gs(1)). If no translation is needed (PostScript printer) the ren- derer's command line reduces to cat(1). The way how this translation is done is described in a PPD file. Printer capabilities, how to handle user options, and how to build the renderer command line is always described by PPD files, these PPD files usually come from Foomatic or can be the ones supplied by the manufacturers of PostScript printers. The PPD files are the same for all spoolers. foomatic-rip works with every known spooler (CUPS, LPRng, LPD, GNUlpr, PPR, PDQ, CPS, and without spooler). It auto-detects the spooler from which it was called by the command line options and environment variables which were supplied by the spooler. Non-PostScript/PDF files are translated to PostScript before they are passed to the renderer. This is usually done by a2ps(1), enscript(1), or mpage(1). foomatic-rip auto-detects which program is installed, but manual configuration is also possible. foomatic-rip does not only apply option settings supplied by the user through the command line of the printing command, but also searches the entire job for embedded option settings (only PostScript jobs). Here not only settings which affect the whole job are taken into account, but also settings in the page headers, which are only valid for the page where they were found, so applications which produce PostScript code with page-specific printer option settings are fully supported. SPOOLER-LESS PRINTING Options -v verbose mode for debugging. WARNING: This will create a file in /tmp that contains the debugging information. This opens a security loophole and should not be used in production. -q quiet mode - minimal information output -P <printer> <printer> is the configured printer which should be used for this job. --ppd <ppdfile> The PPD file <ppdfile> should be applied for processing this job. -J <jobtitle> The <jobtitle> will be printed in the head line of every page of a plain text job. -o <option>=<value> Option settings for this job, do foomatic-rip -P <printer> -o docs <file> (<file> can be an arbitrary existing file, as .bashrc, will not be printed) to print a list of available options for the speci- fied <printer>. <files> The file(s) to be printed. foomatic-rip will print from standard input unless at least one file to be printed is specified on the command line. If your printer PPD file is stored as /etc/direct/<printer>.ppd or ~/.foomatic/direct/<printer>.ppd you can use it by simply specifying "-P <printer>". Put a line *FoomaticRIPPostPipe: "| <command>" into the PPD file, right after *PPD-Adobe: "4.3", where <command> is a command into which you want to re-direct the output data. Due to the restrictions of PPD files <, >, and " are not allowed in the <command>, replace them as follows: Character Replacement --------------------- < &lt; > &gt; " &quot; ' &apos; & &amp; This way you can print directly to your printer, use *FoomaticRIPPostPipe: "| cat &gt; /dev/lp0" or *FoomaticRIPPostPipe: "| cat &gt; /dev/usb/lp0" for local parallel or USB printers. To make normal users able to print this way add them to the group lp and make sure that the appropriate printer device file /dev/... is group-writable for the lp group. for a TCP/Socket/JetDirect printer with the host name printer listening on port 9100 you need this: *FoomaticRIPPostPipe: "| /usr/bin/nc -w 1 printer 9100" Note the "-w 1" in the "nc" command line, it makes "nc" exiting immediately after the data is transferred to the printer. *FoomaticRIPPostPipe: "| rlpr -Plp@printserver" directs your jobs to the LPD printer queue lp on the machine named printserver. See also http://www.openprinting.org/direct-doc.html PRINTING WITH SPOOLER
See the documentation on the OpenPrinting Web site: http://www.openprinting.org/ CONFIGURATION FILE
The file /etc/foomatic/filter.conf is read whenever foomatic-rip is executed. It allows to configure the behavior of foomatic-rip as follows (lines beginning with # are comments and therefore get ignored): textfilter: <command> Selects the filter for input files which are not PostScript or PDF. <command> is one of a2ps, enscript, or mpage. foomatic-rip automatically selects the needed command line options. debug: 0|1 Turns on (1) or off (0) the debug mode. This is equivalent to supplying the --debug command line option. Default setting is 0. ps_accounting: 0|1 Turns on (1) or off (0) inserting PostScript code for page accounting into PostScript jobs. The inserted PostScript code makes Ghostscript generating accounting output on stderr and CUPS can this way log each page which got printed. The code will only be inserted if CUPS is the spooler. Default setting is 1. echo: [<path>/]<executable> Sets the path to an echo(1) executable which supports -n. gspath: [<path>/]<executable> Sets the path to the Ghostscript (gs(1)) executable. To be used if Ghostscript is at a non-standard location or if an alternative Ghostscript should be used. execpath: <path>[:<path>]... Sets the $PATH variable to be used by foomatic-rip. cupsfilterpath: <path>[:<path>]... Sets the directories (colon-separated) in which foomatic-rip searches for CUPS filters. preferred_shell: [<path>/]<executable> Sets the preferred shell to use when executing FoomaticRIPCommandLine and friends. Several PPD files use shell constructs that require a more modern shell like bash, zsh, or ksh. FILES
/etc/cups/ppd/<printer>.ppd /etc/lpd/<printer>.ppd /etc/ppr/<printer>.ppd /etc/pdq/<printer>.ppd /etc/direct/<printer>.ppd The PPD files of the currently defined printers /etc/foomatic/filter.conf Configuration file for foomatic-rip EXIT STATUS
foomatic-rip returns 0 unless something unexpected happens. AUTHOR
Till Kamppeter <till.kamppeter@gmail.com> with parts of Manfred Wassmanns's <manolo@NCC-1701.B.Shuttle.de> man pages for the Foomatic 2.0.x filters. BUGS
None so far. Please send bug reports to the Foomatic mailing list: http://lists.freestandards.org/mailman/listinfo/printing-foomatic Foomatic Project 2002-11-26 FOOMATIC-RIP(1)
All times are GMT -4. The time now is 06:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy