473,834 Members | 1,419 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

find and replace last occurance of letter in string

34 New Member
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 9944
miller
1,089 Recognized Expert Top Contributor
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 New Member
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 Recognized Expert Top Contributor
perldoc perlrequick

- Miller
Jul 4 '07 #4
KevinADC
4,059 Recognized Expert Specialist
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

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

Similar topics

3
17817
by: - ions | last post by:
Hi, i would like to know how to replace every char in a string with a certin given char using the String.replace(char oldChar,char newChar). I would like to replace all letters with an underscore ie. "hello world" will be come... "_ _ _ _ _ _ _ _ _ _" (ive added xtra spaces so it dosnt look like one line!) with the method i have written only the last char is replaced, loop problem i guess! public String hideWord(String word) {
10
33697
by: hokieghal99 | last post by:
import os, string print " " setpath = raw_input("Enter the path: ") def find_replace(setpath): for root, dirs, files in os.walk(setpath): fname = files for fname in files: find = string.find(file(os.path.join(root,fname), 'rb').read(), 'THIS') print find
14
16136
by: Nicolas Bouillon | last post by:
Hi I would like to replace accentuel chars (like "é", "è" or "à") with non accetued ones ("é" -> "e", "è" -> "e", "à" -> "a"). I have tried string.replace method, but it seems dislike non ascii chars... Can you help me please ? Thanks.
3
2705
by: Raed Sawalha | last post by:
I have the following letters; string letters = "a;b;c....to z"; the I need to replace the incoming string which containing letters above with integer 1 i did following for(int u=0;u<letters.Split(';').Length;u++) { FilesName = FilesName.Trim().Replace(letters.Split(';'), "1"); }
4
2195
by: serge | last post by:
I managed to put together C# code and have it do the following: 1- Get all the table names that start with the letter "Z" from sysobjects of my SQL 2000 database and put these table names inside an array variable. 2- Loop through each table name inside the array 1 to 1000 tables
2
1582
by: alacrite | last post by:
With this testprogram: #include <iostream> #include <string> using namespace std; int main() {
10
5661
by: pa2ratczi | last post by:
Hi goo day! I'am Darrel, a newbie with visual basic, i have a problem with my recent project. the projecti have is to replace the text from one letter to another. I dont know how to code it. I'am using text box for my (input), another textbox for the letter to be replace, another text box for the letter to be place. and display the whole text in a label.. can some give me some hint or sample codes. Thank you so much!!! Hoping for an...
2
7223
by: Slippy27 | last post by:
I'm trying to modify a find/replace script which iterates through a file A and makes replacements defined in a csv file B. My original goal was to change any line in file A containing a search string (in whole or as a substring) defined in file B. File B contains both the search string and the string it should be changed into. Example file A whippy slippy ippy slippy snoob flop bloppy
2
1371
by: =?Utf-8?B?TWFya19C?= | last post by:
I am trying to replace any occurance of minus-point "-." with minus-zero-point "-0." My regex: Regex repoint_num = new Regex(@"\-\."); My data: string xyz = "-.9"; My command: repoint_num.Replace(expr, "0."); The match is detected but the replace does not occur.
0
10790
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10505
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10214
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9329
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6952
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5624
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4425
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3079
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.