469,286 Members | 2,547 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,286 developers. It's quick & easy.

find and replace last occurance of letter in string

34
Hi all,
I have a string "Post.lang.tmp.txt" and i have to replase the ".txt" with "_large.txt".

Please help me regarding this problem.

I got it in shell scripting using
`echo $string | awk -F"/" '{print $NF}' | sed s/.txt/_valid.txt/`

Regards
Pnsreee
Jul 4 '07 #1
4 9637
miller
1,089 Expert 1GB
One way:

Expand|Select|Wrap|Line Numbers
  1. my $string = "Post.lang.tmp.txt";
  2. $string =~ s/\.txt$/_large.txt/;
  3. print $string;
  4.  
Another way.

Expand|Select|Wrap|Line Numbers
  1. use File::Basename qw(fileparse);
  2.  
  3. my $string = "Post.lang.tmp.txt";
  4.  
  5. my ($basename) = fileparse($string, '.txt');
  6. my $newstring = "${basename}_large.txt";
  7. print $newstring;
  8.  
- Miller
Jul 4 '07 #2
pnsreee
34
Hi Miller

Thanks for your replay.

I tried with this regexp s/.txt/_valid.txt/ in perl but i did not got it ...

Please tell what $ will do in this regexp

Regards
Pnsreee
Jul 4 '07 #3
miller
1,089 Expert 1GB
perldoc perlrequick

- Miller
Jul 4 '07 #4
KevinADC
4,059 Expert 2GB
Hi Miller

Thanks for your replay.

I tried with this regexp s/.txt/_valid.txt/ in perl but i did not got it ...

Please tell what $ will do in this regexp

Regards
Pnsreee
Why don't you use the regexp Miller posted? The $ on the end of .txt anchors the match to the end of the string.
Jul 4 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by - ions | last post: by
10 posts views Thread by hokieghal99 | last post: by
14 posts views Thread by Nicolas Bouillon | last post: by
3 posts views Thread by Raed Sawalha | last post: by
2 posts views Thread by alacrite | last post: by
2 posts views Thread by =?Utf-8?B?TWFya19C?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.