rename - change n'th character of regexp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting rename - change n'th character of regexp
# 1  
Old 10-06-2009
rename - change n'th character of regexp

Hi,

I wonder if its possible to do the following task using rename (perl v5.8.8).

I want to find filenames matching the specific pattern and then change chosen character of this pattern to a given character, e.g. do the following renaming:
regexp: 'a[12]b' -----> 'a0b'

What's the simplest solution for this? Is one-line rename possible?

Thx!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk or sed to print the character from the previous line after the regexp match

Hi All, I need to print the characters in the previous line just before the regular expression match Please have a look at the input file as attached I need to match the regular expression ^ with the character of the previous like and also the pin numbers and the output file should be like... (6 Replies)
Discussion started by: kshitij
6 Replies

2. Shell Programming and Scripting

Filter non-alpha character with grep/regexp

Hi all, I am trying to filter out those lines that contain a "non-alpha" character. An example of my input is the following: zygnematales grb zygocactus grb zygocactus_truncatus plt zygodactyl_foot prt zygoma prt zygomatic prt zygomatic_arch prt zygomatic_bone ... (2 Replies)
Discussion started by: owwow14
2 Replies

3. Shell Programming and Scripting

Regexp for string that might contain a given character

I'm probably just not thinking of the correct term to search for :-) But I want to match a pattern that might be 'ABC' or '1ABC' there might be three characters, or there might be four, but if there are four, the first has to be 1 (1 Reply)
Discussion started by: jnojr
1 Replies

4. Shell Programming and Scripting

Multiple file rename (change in filename in unix with single command

Dear All, Please help ! i ham having 300 file with E.G. PMC1_4567.arc in seq. like PMC1_4568.arc,PMC1_4569.arc ...n and so on.. i want all those file to be rename like PMC_4567.arc ,PMC_4568.arc .. mean i want to remove 1 from first file name .. pls help.. (6 Replies)
Discussion started by: moon_22
6 Replies

5. UNIX for Dummies Questions & Answers

Doubt with regexp-meta character

Hi, I am learning reg exp a bit :) Meta char info: {n,m} Matches the preceding character at least n times but not more than m times, for example, 'ba{2,3}b' will find 'baab' and 'baaab' but NOT 'bab' or 'baaaab'. Values are enclosed in braces (curly brackets). Input file: 112 11112... (2 Replies)
Discussion started by: dragon.1431
2 Replies

6. UNIX for Dummies Questions & Answers

Shell script to rename or change file extension case.

I searched the forum, but there was different type of rename. Hello. I have files in folder. Like: xxxxxxxx1.html or xxxxxxxx2.txt or xxxxxxxx3.tar.gz and how to rename or change file extension case to xxxxxxxx1.htm or xxxxxxx2.TXT or (5 Replies)
Discussion started by: Sheldon
5 Replies

7. UNIX for Dummies Questions & Answers

print the line immediately after a regexp; but regexp is a sentence

Good Day, Im new to scripting especially awk and sed. I just would like to ask help from you guys about a sed command that prints the line immediately after a regexp, but not the line containing the regexp. sed -n '/regexp/{n;p;}' filename What if my regexp is 3 word or a sentence. Im... (3 Replies)
Discussion started by: ownins
3 Replies

8. Shell Programming and Scripting

Perl RegExp to remove last character from strings

I use SAS (a statistical software) and have to remove last character or the last 1/2 numbers that appear after characters from the string using Perl Regular Expression (which is recognized by SAS). Input: f183ii10 f183ii2 f182ii1 f182ii2 f183iim f22ii f22ii11 f22ii12 pmh4 pmhm Desired... (2 Replies)
Discussion started by: ospreyeagle
2 Replies

9. Shell Programming and Scripting

tcl: regexp matching special character

Hello Experts, Can someone help me here: I have a variable which contains a string with "". set var1 {a} set str1 {a is the element i want to match} Now "regexp $var1 $str1" does not work? ("regexp {a\} $str1" works, but var1 gets it's value automatically from another script) Is... (6 Replies)
Discussion started by: sumitgarg
6 Replies

10. Shell Programming and Scripting

change function structure with perl (regExp)

Hello all i have some function what looks like this class.method("servantName").servantMethod(arg1,arg2,arg3) now i need to convert it to : class.method("servantName","servantMethod",arg1,arg2,arg3); is there any wasy way to do that consider that the arg1+2+3 can be also... (1 Reply)
Discussion started by: umen
1 Replies
Login or Register to Ask a Question
RENAME(1)						 Perl Programmers Reference Guide						 RENAME(1)

NAME
rename - renames multiple files SYNOPSIS
rename [ -v ] [ -n ] [ -f ] perlexpr [ files ] DESCRIPTION
"rename" renames the filenames supplied according to the rule specified as the first argument. The perlexpr argument is a Perl expression which is expected to modify the $_ string in Perl for at least some of the filenames specified. If a given filename is not modified by the expression, it will not be renamed. If no filenames are given on the command line, filenames will be read via standard input. For example, to rename all files matching "*.bak" to strip the extension, you might say rename 's/.bak$//' *.bak To translate uppercase names to lower, you'd use rename 'y/A-Z/a-z/' * OPTIONS
-v, --verbose Verbose: print names of files successfully renamed. -n, --no-act No Action: show what files would have been renamed. -f, --force Force: overwrite existing files. ENVIRONMENT
No environment variables are used. AUTHOR
Larry Wall SEE ALSO
mv(1), perl(1) DIAGNOSTICS
If you give an invalid Perl expression you'll get a syntax error. BUGS
The original "rename" did not check for the existence of target filenames, so had to be used with care. I hope I've fixed that (Robin Barker). perl v5.14.2 2014-09-26 RENAME(1)