LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-21-2009, 02:29 AM   #1
nrg
LQ Newbie
 
Registered: Nov 2009
Posts: 8

Rep: Reputation: 0
Simple regex match without replace?


I'm currently doing this:

Code:
perl -pe 's/.+\/(.+)/\1/')
Which will replace

Code:
path/to/myfile.exe
with

Code:
myfile.exe
-- How do I retrieve "myfile.exe" without a replace statement?

For clarification, I have two files, ivy.xml and build.xml.

Ivy.xml line:

Code:
<dependency org="com.project" name="my-service" rev="2.9.1"/>
Build.xml line:

Code:
<unzip src="${ivy.resolved.lib.dir}/my-service-2.9.0.jar" dest="${classes.dir}" />
I am trying to update the build.xml line with the ivy.xml version, so I need to run the following regex:

Code:
my-service\"\ rev=\"(.+)\"
so I can grab \1 as, for example $code, then run:

Code:
perl -p -i -e "s/(.+my-service-)(.+?)(\.jar.+)\.jar.+/\1$code\3/"
on build.xml, thus updating the version.

On a related note, that last perl line doesn't seem like the right way to go about it -- is there a way to match the line, specific to the service, but only update a section thereof?
 
Old 11-21-2009, 04:04 AM   #2
nrg
LQ Newbie
 
Registered: Nov 2009
Posts: 8

Original Poster
Rep: Reputation: 0
In answer to my original question, this is what I ended up with:

Code:
buildversion=$(echo $service-name|perl -pe "s/.+\-(.+)\.j.+/\1/")
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What should some Regex match in awk? sebelk Programming 7 11-20-2009 07:38 PM
Help with regex to match an IP abefroman Linux - Server 5 11-02-2009 04:07 PM
Extract everything before a regex match onesikgypo Programming 5 10-21-2009 05:49 AM
Perl Regex multiline match issues adymcc Linux - General 2 03-31-2008 10:45 AM
help me match this regex line (easy) JustinHoMi Programming 7 03-17-2002 02:43 AM


All times are GMT -5. The time now is 05:03 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration