The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help with finding & replacing pattern in a file dusoo Shell Programming and Scripting 0 05-23-2008 03:59 AM
finding duplicate files by size and finding pattern matching and its count jerome Sukumar Shell Programming and Scripting 2 12-01-2006 04:20 AM
Pattern Recognition - perl scorreg UNIX for Dummies Questions & Answers 3 09-23-2006 09:41 AM
Finding pattern & prepending a line with text kirrushna Shell Programming and Scripting 1 07-11-2006 02:20 AM
Finding a specific pattern from thousands of files ???? aarora_98 Shell Programming and Scripting 6 02-17-2006 08:28 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-03-2008
hkjang hkjang is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1
Perl: finding pattern and substituting

In Perl, I know pattern matching is something like, $name =~ /xxxxxx/;
If I find pattern matching using regular expression, how do I substitute it with real string?
For example, I need to find pattern, /-\d\d\d\d/, which is something like "-2000", but those 4 digits can be any numbers.
Now, I need to replace those numbers with "-<certain 4 digit number>".
Is there a way to do it in Perl?
Thank a bunch in advance!!!
  #2 (permalink)  
Old 03-03-2008
matt.d's Avatar
matt.d matt.d is offline
Registered User
  
 

Join Date: Feb 2008
Location: /dev/null
Posts: 62
Yes -- you use the substitution syntax:

s/<regex you want to find>/<string you want to substitute/

Example: s/matt/MATT/ will substitute "matt" with "MATT."

Incidentally, another way to do your regex would be /-[0-9]{4}/ and you could do your substitution like: s/-[0-9]{4}/string/
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:51 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0