LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 01-20-2009, 01:47 PM   #1
maginotjr
Member
 
Registered: Aug 2004
Location: BR - Floripa
Distribution: Ubuntu 9.10 - 2.6.x.x
Posts: 661

Rep: Reputation: 35
Regexp for changing only part of the found string


Hi!

I love regex but sometimes I get crazy trying to figure out things... I hope you can help me...

here is the thing, I have to find all the ',' inside a large database dumb, but this ',' are only in this kind of mask:
$ANYNUMBER-ANYQTD,ANYNUMBER-ANYQTD$
Actualy the $ is not the regex end of line special operator. (I had to use something like $ to avoid the " and ' inside text fields that were dumped).
Here is the regex Im trying (Im in vim):

%s/\$[0-9]+[,][0-9]+\$/I DONT KNOW HOW TO CHANGE ONLY THE DOT/g


well... I couldnt understand why the above dont even match any line if I have lines like $0,01$, $100,14$ and want they to became $0.01$, $100.14$ and so on...


thks!
 
Old 01-20-2009, 02:35 PM   #2
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
Please post a larger sample of the file that you are trying to modify.

Will there be other commas in the file (that need to stay as commas)?

If not why not just try (within vi)
:1,$ s/,/./g
 
Old 01-20-2009, 03:43 PM   #3
jstephens84
Senior Member
 
Registered: Sep 2004
Location: Nashville
Distribution: Manjaro, RHEL, CentOS
Posts: 2,098

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by maginotjr View Post
Hi!

I love regex but sometimes I get crazy trying to figure out things... I hope you can help me...

here is the thing, I have to find all the ',' inside a large database dumb, but this ',' are only in this kind of mask:
$ANYNUMBER-ANYQTD,ANYNUMBER-ANYQTD$
Actualy the $ is not the regex end of line special operator. (I had to use something like $ to avoid the " and ' inside text fields that were dumped).
Here is the regex Im trying (Im in vim):

%s/\$[0-9]+[,][0-9]+\$/I DONT KNOW HOW TO CHANGE ONLY THE DOT/g


well... I couldnt understand why the above dont even match any line if I have lines like $0,01$, $100,14$ and want they to became $0.01$, $100.14$ and so on...


thks!
Use (1st part of exp) (second part of exp) / $1.$2 / I believe that is what you will want to do. This will break the exp into two delimited. so 1,00 would be $1 = 1 and $2 = 00.
 
Old 01-20-2009, 04:52 PM   #4
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
I think you meant, from within vi:
Code:
:1,$ s/\([0-9]\),\([0-9]\)/\1.\2/g
or using sed:
Code:
sed -i 's/\([0-9]\),\([0-9]\)/\1.\2/g' file
 
Old 01-21-2009, 04:27 AM   #5
maginotjr
Member
 
Registered: Aug 2004
Location: BR - Floripa
Distribution: Ubuntu 9.10 - 2.6.x.x
Posts: 661

Original Poster
Rep: Reputation: 35
Hey, thanks! The SED example worked fine here, but the VI example didnt, althought it worked was not the right way, like describle in the mask and like the way sed did...

but thanks for the both

[ ]'s
 
  


Reply



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
Extract part of a string steven.c.banks Linux - General 7 05-07-2008 07:18 AM
Shell Script: Delete lines til string found or until particular string. bhargav_crd Linux - General 3 12-20-2007 11:14 PM
LXer: Open Source: Changing Models, Changing Mindsets, Part 1 LXer Syndicated Linux News 0 08-23-2007 04:30 AM
Perl/regexp help... - query string parsing... lowpro2k3 Programming 4 05-11-2005 05:18 PM
Keeping part of a regexp in search/replace MadCactus Linux - General 4 09-29-2004 06:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:56 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration