Sponsored Content
Full Discussion: Copy files help needed
Top Forums Shell Programming and Scripting Copy files help needed Post 302170822 by pflynn on Tuesday 26th of February 2008 09:16:06 PM
Old 02-26-2008
An alternative solution, this time using just the shell, without the help of external programs (except by the cp program, of course):

PHP Code:
for file in *5001*; do cp $file ${file/01/06};done 
the key here is the ${//} shell's parameter expansion operator:

extracted from GNU Bash man page:

Quote:
${parameter/pattern/string}
${parameter//pattern/string}
The pattern is expanded to produce a pattern just as in pathname expansion. Parameter is expanded and the longest match of pattern against its value is
replaced with string. In the first form, only the first match is replaced. The second form causes all matches of pattern to be replaced with string.
If pattern begins with #, it must match at the beginning of the expanded value of parameter. If pattern begins with %, it must match at the end of the
expanded value of parameter. If string is null, matches of pattern are deleted and the / following pattern may be omitted. If parameter is @ or *, the
substitution operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable sub-
scripted with @ or *, the substitution operation is applied to each member of the array in turn, and the expansion is the resultant list.
this operator is available on the Korn Shell to.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help needed in Listing Files

I need to list files in alphabetical-group and each such group listed in increasing order of timestamp. Example : If I list files in a directory ( ls -lrt ) it shows like below. c3 b4 b3 a4 a3 c2 b2 c1 b1 a2 a1 What I need is c3 c2 (4 Replies)
Discussion started by: coolbhai
4 Replies

2. UNIX for Dummies Questions & Answers

Help needed in deleting the files

Hi, I wanted to check whether any files are available under the path /usr/app/logs/. If the files are available under this path then i have to delete all the files except the files system.log, system.log.1, system.log.2 and sub folders under this path Can any one please help me on this? ... (2 Replies)
Discussion started by: Sheethal
2 Replies

3. Shell Programming and Scripting

help needed in grep and copy

need help in a command. My requirement is that i m grepping the filename based on a pattern in .tar.gz file and then copying the file into some dir below is what exactly i want to achieve step 1: grep -l '30017A6800022D1A' CurrentCollectorMeterReadBackup20081007.tar.gz step 2: file found... (2 Replies)
Discussion started by: ali560045
2 Replies

4. Shell Programming and Scripting

Help needed for deleting the files.

Hi guys i m trying to delete some files from one of the share which is mounted on my machine. but whenever i do that it says access denied. I m logged in as a root for my machine. below is the output for those two file. mount command for mounting the shares. mount... (1 Reply)
Discussion started by: pinga123
1 Replies

5. UNIX for Dummies Questions & Answers

Help needed to backup files.

Hi guys , I m writing a script which will backup a particular folder and its content to a different location. this script needs to be run every weekend. But my problem is how would i apply logic such that the previous backup folder is only deleted if and only if the current backup is... (1 Reply)
Discussion started by: pinga123
1 Replies

6. Solaris

Solaris 6.5 MOD disk copy help needed

Hello, we are running Irix 6.5 on our octane/sgi computers - these computers come with an external Sony MOD drive attached via a scsi cable. We have backed info to 2.3 gig MOD disks over the years and woule like to duplicate the MOD's. I believe there are 3 ways to do this: add a second... (1 Reply)
Discussion started by: drew_holm
1 Replies

7. Solaris

How to safely copy full filesystems with large files (10Gb files)

Hello everyone. Need some help copying a filesystem. The situation is this: I have an oracle DB mounted on /u01 and need to copy it to /u02. /u01 is 500 Gb and /u02 is 300 Gb. The size used on /u01 is 187 Gb. This is running on solaris 9 and both filesystems are UFS. I have tried to do it using:... (14 Replies)
Discussion started by: dragonov7
14 Replies

8. Shell Programming and Scripting

how to copy files followed by list of names of all the files in /etc?

....... (2 Replies)
Discussion started by: pcbuilder
2 Replies

9. Red Hat

Unable to copy files due to many files in directory

I have directory that has some billion file inside , i tried copy some files for specific date but it's always did not respond for long time and did not give any result.. i tried everything with find command and also with xargs.. even this command find . -mtime -2 -print | xargs ls -d did not... (2 Replies)
Discussion started by: before4
2 Replies

10. UNIX for Dummies Questions & Answers

Copy files from one drive to another, keeping most recently modified files

Hi all, I am a bit of a beginner with shell scripting.. What I want to do is merge two drives, for example moving all data from X to Y. If a file in X doesn't exist in Y, it will be moved there. If a file in X also exists in Y, the most recently modified file will be moved to (or kept) in... (5 Replies)
Discussion started by: apocolapse
5 Replies
MB_EREG_REPLACE(3)							 1							MB_EREG_REPLACE(3)

mb_ereg_replace - Replace regular expression with multibyte support

SYNOPSIS
string mb_ereg_replace (string $pattern, string $replacement, string $string, [string $option = "msr"]) DESCRIPTION
Scans $string for matches to $pattern, then replaces the matched text with $replacement PARAMETERS
o $pattern - The regular expression pattern. Multibyte characters may be used in $pattern. o $replacement - The replacement text. o $string - The string being checked. o $option - Matching condition can be set by $option parameter. If i is specified for this parameter, the case will be ignored. If x is specified, white space will be ignored. If m is specified, match will be executed in multiline mode and line break will be included in '.'. If p is specified, match will be executed in POSIX mode, line break will be considered as normal character. If e is specified, $replacement string will be evaluated as PHP expression. RETURN VALUES
The resultant string on success, or FALSE on error. NOTES
Note The internal encoding or the character encoding specified by mb_regex_encoding(3) will be used as the character encoding for this function. Warning Never use the e modifier when working on untrusted input. No automatic escaping will happen (as known from preg_replace(3)). Not taking care of this will most likely create remote code execution vulnerabilities in your application. SEE ALSO
mb_regex_encoding(3), mb_eregi_replace(3). PHP Documentation Group MB_EREG_REPLACE(3)
All times are GMT -4. The time now is 04:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy