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


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?

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
shevek::regexp(3)					     Library Functions Manual						 shevek::regexp(3)

shevek::regexp - Use regular expressions. SYNOPSIS
#include <regexp.hh> Public Member Functions regexp (std::string const &pattern=std::string(), bool case_sensitive=false) Create a new object, and optionally fill it with a pattern. regexp & operator= (std::string const &pattern) Set a pattern, removing the previous one. regexp (regexp const &that) Copy a regexp. regexp & operator= (regexp const &that) Copy a regexp. void case_sensitive (bool value=true) Set whether the evaluation should be case sensitive. ~regexp () Destructor, this cleans up internal structures. bool operator() (std::string const &data) Check whether the pattern matches a string, and fill internal match structures if it does. std::string operator[] (unsigned idx) const Retrieve the value of a subexpression from the last matched string. bool valid (unsigned idx) const Test whether a subexpression was filled by the last matching string. unsigned size () const Get the number of subexpression. std::string transform (std::string const &data) const Transform a string with -codes according to the last matching string. std::string const & pattern () const Get the current pattern. Detailed Description Use regular expressions. Member Function Documentation std::string shevek::regexp::operator[] (unsignedidx) const Retrieve the value of a subexpression from the last matched string. This throws an exception if the subexpression is not valid. Author Generated automatically by Doxygen for libshevek from the source code. libshevek Fri May 11 2012 shevek::regexp(3)

Featured Tech Videos