Hello All,
I would like the replace the following string,
TRANS -847.0 -672.0 -71.0
as
TRANS -840.0 -660.0 -62.0
I am able to replace the string when the numbers are positive without decimals using \d and \s syntax. But the above expressions have negative sign and decimals. How could i formulate that using regexp.
Ramesh
9 1138
What have you tried thus far? I would love to see what you come up with and will then help you from there. Do not forget to post your code (in code tags) and any errors or results.
Regards,
Jeff
- #!\usr\bin\perl
-
use warnings;
-
use strict;
-
open IN,"+< z.txt";
-
open OUT,"> t.txt";
-
while (<IN>) {
-
s/(\d+)\s+(\d+)\s+(\d+)/ ($1+7).$2. ($3+12).$2.($4+9)/g;
-
print OUT;
-
}
This works when numbers are positive integers. My case is for decimals and negative numbers.
Do not forget to post your code (in code tags)
oops...... hehehe
oops...... hehehe
Maybe numberwhun won't notice.
- my $str = 'TRANS -847.0 -672.0 -71.0';
-
$str =~ s/(\S+)\s+(-?\d+\.?\d?)\s+(-?\d+\.?\d?)\s+(-?\d+\.?\d?)/sprintf "$1 %.1f %.1f %.1f", $2+7,$3+12,$4+9/eg;
-
print $str;
Thanks Kevin for the help. It replaces the negative and decimal numbers.
Thanks Kevin for the help. It replaces the negative and decimal numbers.
Next time use the CODE tags, OK? If not, Jeff might ban you from the forum.
Next time use the CODE tags, OK? If not, Jeff might ban you from the forum.
I am not that cruel, I give a couple warnings. :-) Don't you have a rebellion to worry about Kevin?
I am not that cruel, I give a couple warnings. :-) Don't you have a rebellion to worry about Kevin?
No, the rebellion was postponed, maybe cancelled, depends on if my wife comes to her senses.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: C# Learner |
last post by:
What's the "standard" way of replacing a character in a string?
Obviously, I can't say "myString = character;" because strings
are immutable...
So what would be the "standard" way of doing this?...
|
by: VMI |
last post by:
If I have the string "Héllo", how can I replace char (é) with an 'e'? I
cannot use the String.Replace() fuction. It has to be by replacing one char
with another.
Thanks.
|
by: Ryan Taylor |
last post by:
Hi.
I have some code that dynamically generates a PDF and spits this content
directly to the web browser. I use HTMLDoc to create the Pdf's from html. So
the user can click on a button "Print...
|
by: Adam J. Schaff |
last post by:
I am writing a quick program to edit a binary file that contains file paths
(amongst other things). If I look at the files in notepad, they look like:
...
|
by: WT |
last post by:
Hello,
I was using hastable to store collection of objects of the same class
MyClass.
I start replacing this hastable by a Dictionary<string,MyClass>....but
I was storing this hastable in cache...
|
by: Alain |
last post by:
Hi,
I am working on a project where I need to convert international characters
with acii values. Like André -> andre and Björn -> bjorn.
How can I do this without replacing every single...
|
by: FireHead |
last post by:
Hello C World & Fanatics
I am trying replace fgets and provide a equavivalant function of
BufferedInputReader::readLine.
I am calling this readLine function as get_Stream.
In the line 4 where...
|
by: Lakhi |
last post by:
hi frnds,
I need small help in String replacement
I need to replace the text using replceAll() with Case-Insensitve .
Is there any regular expression for this?
i have this expression ...
|
by: gsuns82 |
last post by:
Hi all,
I have to replace accented characters from a input string with
normal plain text.I have coded as follows.
String input = "ÄÀÁÂÃ";
input=...
|
by: DarthBob88 |
last post by:
I have to go through a file and replace any occurrences of a given
string with the desired string, like replacing "bug" with "feature".
This is made more complicated by the fact that I have to do...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
| |