LinuxQuestions.org
Visit Jeremy's Blog.
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 03-23-2007, 03:23 AM   #1
vippie
LQ Newbie
 
Registered: Mar 2007
Posts: 3

Rep: Reputation: 0
Perl: replace character in file


Hello,

I've read all the topics on this problem, the solution works, but not for my specific problem.

I want to replace a dot by a comma in a .txt file

This should be possible by doing this on the command line:

/usr/bin/perl -p -i.bak -e "s/./,/g" *.txt

This returns the *.txt file full with comma's (and a .bak backup file), it replaced every character with a comma.

If I do this:

/usr/bin/perl -p -i.bak -e "s/i/,/g" *.txt

then it works fine and it replaces every 'i' with a comma.

So it seems it does work with every character, except dots


It might be a noobisch question, but can somebody help me to fix this?
 
Old 03-23-2007, 03:24 AM   #2
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Rep: Reputation: 30
this would work,

Code:
s/\./,/g
 
Old 03-23-2007, 03:26 AM   #3
vippie
LQ Newbie
 
Registered: Mar 2007
Posts: 3

Original Poster
Rep: Reputation: 0
thanks for the fast reply, it works

(this is my first day programming perl)
 
Old 03-23-2007, 03:37 AM   #4
son_t
Member
 
Registered: Sep 2006
Posts: 49

Rep: Reputation: 15
Quote:
Originally Posted by vippie
thanks for the fast reply, it works

(this is my first day programming perl)
But do you understand? The '.' means match any character, so if you want to match the literal '.', you have to escape it with a \.
 
Old 03-23-2007, 04:26 AM   #5
vippie
LQ Newbie
 
Registered: Mar 2007
Posts: 3

Original Poster
Rep: Reputation: 0
Yes, I understand now, figured that . means every character. Didn't know about the '\' escape
 
  


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
Perl replace text in file ShaqDiesel Programming 27 08-11-2010 10:50 PM
find certain character and replace with a number yongitz Programming 1 01-18-2007 07:40 AM
Perl - Tpl file - Need to replace new line character. knnirmal Programming 2 09-07-2004 02:27 PM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
problem in perl replace command with slash (/) in search/replace string ramesh_ps1 Red Hat 4 09-10-2003 01:04 AM

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

All times are GMT -5. The time now is 08:15 PM.

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