Sponsored Content
Top Forums Shell Programming and Scripting perl : regular expression to replace the strings Post 302702325 by giridhar276 on Tuesday 18th of September 2012 06:18:48 AM
Old 09-18-2012
perl : regular expression to replace the strings

There are 2 strings as below.

Code:
$str1 = "41148,,,,,,,,,,,,,,,,,,,,,,,,";
$date = "TUE 08-28-2012";

The output should be as below
Code:
 
$str1 = "TUE 08-28-2012,,,,,,,,,,,,,,,,,,,,,,,,";

Could anyone please help with the perl regular expression or any other alternative?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl regular expression

letz say that my file has 7 records with only one field. So my file has: 11111111 000000000000000 1111 aaaabbbccc 1111111222000000 aaaaaaaa zz All i need is: 1. when the field has a repetition of the same instance(a-z or 0-9), i would consideer it to be invalid.... (1 Reply)
Discussion started by: helengoldman
1 Replies

2. UNIX for Dummies Questions & Answers

Regular Expression - Replace if x contains y except if...

Hi all, I have a file which contains 1000s of lines of text. I need to delete all lines with the words "Red" EXCEPT if the line also contains the word "GREEN"... For example: ThisIs some random text that should be red deleted ThisIs some random text that should NOT be red deleted green ... (4 Replies)
Discussion started by: not4google
4 Replies

3. Shell Programming and Scripting

regular expression in perl

hi, i want to extract the sessionID from this line. QnA Session Id : here the output should be-- QnA_SessionID=128589 Thanks NT (3 Replies)
Discussion started by: namishtiwari
3 Replies

4. UNIX for Dummies Questions & Answers

replace words in sed using regular expression

hi, I need to replace all these lines from my text file 123end 234end 324end 234end 989end 258end 924end At the moment I know how to replace "end". But I want to replace the numbers before end as well. How can I do this ? sed s/end/newWord/ myfile.txt newFile.txt thanks (3 Replies)
Discussion started by: aneuryzma
3 Replies

5. Shell Programming and Scripting

PERL regular expression

Hello all, I need to match the red expressions in the following lines : MACRO_P+P-_scrambledServices_REM_PRC30.xml MACRO_P+P-_scrambledServices_REM_RS636.xml MACRO_P+P-_scrambledServices_REM_RS535.xml and so on... Can anyone give me a PERL regular expression to match those characters ? ... (5 Replies)
Discussion started by: lsaas
5 Replies

6. Shell Programming and Scripting

perl regular expression

Dear all, I have a simple issue on a perl regular expression. I want to get the characters in red from the next lines : POWER_key LEFT_key RIGHT_key OK_key DOWN_key and so on... Thanks in advance for reply. Ludo (1 Reply)
Discussion started by: lsaas
1 Replies

7. Shell Programming and Scripting

Perl regular expression and %

Could you help me with this please. This regular expression seems to match for the wrong input #!/usr/bin/perl my $inputtext = "W1a$%XXX"; if($inputtext =~ m/+X+/) { print "matches\n"; } The problem seems to be %. if inputtext is W1a$XXX, the regex doesnot match.... (5 Replies)
Discussion started by: suppandi7
5 Replies

8. Shell Programming and Scripting

Hidden Characters in Regular Expression Matching Perl - Perl Newbie

I am completely new to perl programming. My father is helping me learn said programming language. However, I am stuck on one of the assignments he has given me, and I can't find very much help with it via google, either because I have a tiny attention span, or because I can be very very dense. ... (4 Replies)
Discussion started by: kittyluva2
4 Replies

9. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

10. Shell Programming and Scripting

Perl regular expression

Hi , I have the below array my @actionText = ("delivered to governor on 21/23/3345" , "deliver jllj" , "ram 2345/43"); When i am trying to grep the contents of array and if mathced substituting with the digitis or some date format from the element like below my @action = grep { $_ =~... (7 Replies)
Discussion started by: ragilla
7 Replies
STRNATCMP(3)								 1							      STRNATCMP(3)

strnatcmp - String comparisons using a ";natural order" algorithm

SYNOPSIS
int strnatcmp (string $str1, string $str2) DESCRIPTION
This function implements a comparison algorithm that orders alphanumeric strings in the way a human being would, this is described as a "natural ordering". Note that this comparison is case sensitive. PARAMETERS
o $str1 - The first string. o $str2 - The second string. RETURN VALUES
Similar to other string comparison functions, this one returns < 0 if $str1 is less than $str2; > 0 if $str1 is greater than $str2, and 0 if they are equal. EXAMPLES
An example of the difference between this algorithm and the regular computer string sorting algorithms (used in strcmp(3)) can be seen below: <?php $arr1 = $arr2 = array("img12.png", "img10.png", "img2.png", "img1.png"); echo "Standard string comparison "; usort($arr1, "strcmp"); print_r($arr1); echo " Natural order string comparison "; usort($arr2, "strnatcmp"); print_r($arr2); ?> The above example will output: Standard string comparison Array ( [0] => img1.png [1] => img10.png [2] => img12.png [3] => img2.png ) Natural order string comparison Array ( [0] => img1.png [1] => img2.png [2] => img10.png [3] => img12.png ) SEE ALSO
preg_match(3), strcasecmp(3), substr(3), stristr(3), strcmp(3), strncmp(3), strncasecmp(3), strnatcasecmp(3), strstr(3), natsort(3), nat- casesort(3). PHP Documentation Group STRNATCMP(3)
All times are GMT -4. The time now is 11:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy