Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Moving files by splitting the path embedded in the filename Post 69088 by vgersh99 on Monday 11th of April 2005 03:29:13 PM
Old 04-11-2005
wouldn't it be easier to simply substitute '@#' with '/' and copy the files?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

moving files with spaces in filename from one directory to another

Hello, When I run following script #!/bin/bash cd ~/directory1 mv `ls -trF | grep -v / | tail -10 ` ~/directory2 works fine with filenames not having any space but runs into issues with filenames that have spaces tried with $file variable still doesnot work. Can someone help me (4 Replies)
Discussion started by: asakhare
4 Replies

2. Shell Programming and Scripting

Filename from splitting files to have the same filename of the original file with counter value

Hi all, I have a list of xml file. I need to split the files to a different files when see the <ko> tag. The list of filename are B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml ... (3 Replies)
Discussion started by: natalie23
3 Replies

3. Shell Programming and Scripting

Problem with embedded FTP command in Ksh - System Cannot find the specified path.

I have the following FTP embedded in a Ksh script on AIX 5.3 ftp -n <<WHATEVER open 10.101.26.218 user hcistats ******* ascii put $thupdatefile put $thcollectfile quit WHATEVER Here is what my script returns: ... (3 Replies)
Discussion started by: troym72
3 Replies

4. Shell Programming and Scripting

How to remove filename from the path

Hi, I have a list of paths with files at the end. How can strip off filenames. This is what I have: /apps/test/abc/file.txt /apps/new/home/daily/report.xml /apps/old/home/weekly/out/test.sh This is what I need: /apps/test/abc/ /apps/new/home/daily/ /apps/old/home/weekly/out/ ... (10 Replies)
Discussion started by: djanu
10 Replies

5. UNIX for Dummies Questions & Answers

finding and moving files based on the last three numerical characters in the filename

Hi, I have a series of files (upwards of 500) the filename format is as follows CC10-1234P1999.WGS84.p190, all in one directory. Now the last three numeric characters, in this case 999, can be anything from 001 to 999. I need to move some of them to a seperate directory, the ones I need to... (5 Replies)
Discussion started by: roche.j.mike
5 Replies

6. Shell Programming and Scripting

How to add filepath to filename when moving it?

Hi I have a cron job setup that searches for 'core dump' files in a fixed set of directories and moves the core files to a separate file system. I am able to add date and time info to the file name. How can I add the source directory path to the file name? In case anyone is wondering why I... (5 Replies)
Discussion started by: dexter126
5 Replies

7. Solaris

Moving a zone path to a new file system

Hello Gurus, I need your help with this please. I am trying to move a zone to a new directory but it keeps failing. Below is what I did and the message I get. Your help will be appreciated. Thanks zoneadm -z testzone move /rpool/testzone cannot create ZFS dataset rpool/testzone: dataset... (1 Reply)
Discussion started by: cjashu
1 Replies

8. Shell Programming and Scripting

Non trivial file splitting, saving with variable filename

Hello, Although I have found similar questions, I could not find advice that could help with our problem. The issue: We have a few thousands text files (books). Each book has many chapters. Each chapter is identified by a cite-key. We need to split each of those book files by... (4 Replies)
Discussion started by: samask
4 Replies

9. Shell Programming and Scripting

Moving files from parent path to multiple child path using bash in efficient way

Hi All, Can you please provide some pointers to move files from Base path to multiple paths in efficient way.Folder Structure is already created. /Path/AdminUser/User1/1111/Reports/aaa.txt to /Path/User1/1111/Reports/aaa.txt /Path/AdminUser/User1/2222/Reports/bbb.txt to... (6 Replies)
Discussion started by: karthikgv417
6 Replies

10. Open Source

Splitting files using awk and reading filename value from input data

I have a process that requires me to read data from huge log files and find the most recent entry on a per-user basis. The number of users may fluctuate wildly month to month, so I can't code for it with names or a set number of variables to capture the data, and the files are large so I don't... (7 Replies)
Discussion started by: rbatte1
7 Replies
File::GlobMapper(3pm)					 Perl Programmers Reference Guide				     File::GlobMapper(3pm)

NAME
File::GlobMapper - Extend File Glob to Allow Input and Output Files SYNOPSIS
use File::GlobMapper qw( globmap ); my $aref = globmap $input => $output or die $File::GlobMapper::Error ; my $gm = new File::GlobMapper $input => $output or die $File::GlobMapper::Error ; DESCRIPTION
This module needs Perl5.005 or better. This module takes the existing "File::Glob" module as a starting point and extends it to allow new filenames to be derived from the files matched by "File::Glob". This can be useful when carrying out batch operations on multiple files that have both an input filename and output filename and the output file can be derived from the input filename. Examples of operations where this can be useful include, file renaming, file copying and file compression. Behind The Scenes To help explain what "File::GlobMapper" does, consider what code you would write if you wanted to rename all files in the current directory that ended in ".tar.gz" to ".tgz". So say these files are in the current directory alpha.tar.gz beta.tar.gz gamma.tar.gz and they need renamed to this alpha.tgz beta.tgz gamma.tgz Below is a possible implementation of a script to carry out the rename (error cases have been omitted) foreach my $old ( glob "*.tar.gz" ) { my $new = $old; $new =~ s#(.*).tar.gz$#$1.tgz# ; rename $old => $new or die "Cannot rename '$old' to '$new': $! ; } Notice that a file glob pattern "*.tar.gz" was used to match the ".tar.gz" files, then a fairly similar regular expression was used in the substitute to allow the new filename to be created. Given that the file glob is just a cut-down regular expression and that it has already done a lot of the hard work in pattern matching the filenames, wouldn't it be handy to be able to use the patterns in the fileglob to drive the new filename? Well, that's exactly what "File::GlobMapper" does. Here is same snippet of code rewritten using "globmap" for my $pair (globmap '<*.tar.gz>' => '<#1.tgz>' ) { my ($from, $to) = @$pair; rename $from => $to or die "Cannot rename '$old' to '$new': $! ; } So how does it work? Behind the scenes the "globmap" function does a combination of a file glob to match existing filenames followed by a substitute to create the new filenames. Notice how both parameters to "globmap" are strings that are delimited by <>. This is done to make them look more like file globs - it is just syntactic sugar, but it can be handy when you want the strings to be visually distinctive. The enclosing <> are optional, so you don't have to use them - in fact the first thing globmap will do is remove these delimiters if they are present. The first parameter to "globmap", "*.tar.gz", is an Input File Glob. Once the enclosing "< ... >" is removed, this is passed (more or less) unchanged to "File::Glob" to carry out a file match. Next the fileglob "*.tar.gz" is transformed behind the scenes into a full Perl regular expression, with the additional step of wrapping each transformed wildcard metacharacter sequence in parenthesis. In this case the input fileglob "*.tar.gz" will be transformed into this Perl regular expression ([^/]*).tar.gz Wrapping with parenthesis allows the wildcard parts of the Input File Glob to be referenced by the second parameter to "globmap", "#1.tgz", the Output File Glob. This parameter operates just like the replacement part of a substitute command. The difference is that the "#1" syntax is used to reference sub-patterns matched in the input fileglob, rather than the $1 syntax that is used with perl regular expressions. In this case "#1" is used to refer to the text matched by the "*" in the Input File Glob. This makes it easier to use this module where the parameters to "globmap" are typed at the command line. The final step involves passing each filename matched by the "*.tar.gz" file glob through the derived Perl regular expression in turn and expanding the output fileglob using it. The end result of all this is a list of pairs of filenames. By default that is what is returned by "globmap". In this example the data structure returned will look like this ( ['alpha.tar.gz' => 'alpha.tgz'], ['beta.tar.gz' => 'beta.tgz' ], ['gamma.tar.gz' => 'gamma.tgz'] ) Each pair is an array reference with two elements - namely the from filename, that "File::Glob" has matched, and a to filename that is derived from the from filename. Limitations "File::GlobMapper" has been kept simple deliberately, so it isn't intended to solve all filename mapping operations. Under the hood "File::Glob" (or for older versions of Perl, "File::BSDGlob") is used to match the files, so you will never have the flexibility of full Perl regular expression. Input File Glob The syntax for an Input FileGlob is identical to "File::Glob", except for the following 1. No nested {} 2. Whitespace does not delimit fileglobs. 3. The use of parenthesis can be used to capture parts of the input filename. 4. If an Input glob matches the same file more than once, only the first will be used. The syntax ~ ~user . Matches a literal '.'. Equivalent to the Perl regular expression . * Matches zero or more characters, except '/'. Equivalent to the Perl regular expression [^/]* ? Matches zero or one character, except '/'. Equivalent to the Perl regular expression [^/]? Backslash is used, as usual, to escape the next character. [] Character class. {,} Alternation () Capturing parenthesis that work just like perl Any other character it taken literally. Output File Glob The Output File Glob is a normal string, with 2 glob-like features. The first is the '*' metacharacter. This will be replaced by the complete filename matched by the input file glob. So *.c *.Z The second is Output FileGlobs take the "*" The "*" character will be replaced with the complete input filename. #1 Patterns of the form /#d/ will be replaced with the Returned Data EXAMPLES
A Rename script Below is a simple "rename" script that uses "globmap" to determine the source and destination filenames. use File::GlobMapper qw(globmap) ; use File::Copy; die "rename: Usage rename 'from' 'to' " unless @ARGV == 2 ; my $fromGlob = shift @ARGV; my $toGlob = shift @ARGV; my $pairs = globmap($fromGlob, $toGlob) or die $File::GlobMapper::Error; for my $pair (@$pairs) { my ($from, $to) = @$pair; move $from => $to ; } Here is an example that renames all c files to cpp. $ rename '*.c' '#1.cpp' A few example globmaps Below are a few examples of globmaps To copy all your .c file to a backup directory '</my/home/*.c>' '</my/backup/#1.c>' If you want to compress all '</my/home/*.[ch]>' '<*.gz>' To uncompress '</my/home/*.[ch].gz>' '</my/home/#1.#2>' SEE ALSO
File::Glob AUTHOR
The File::GlobMapper module was written by Paul Marquess, pmqs@cpan.org. COPYRIGHT AND LICENSE
Copyright (c) 2005 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.16.2 2012-10-11 File::GlobMapper(3pm)
All times are GMT -4. The time now is 09:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy