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
perl script for file processing SEEHTAS Shell Programming and Scripting 10 03-25-2008 09:02 AM
processing a file with sed and awk manouche Shell Programming and Scripting 4 10-11-2007 04:25 PM
Processing a CSV file janemary.a High Level Programming 1 05-11-2007 06:27 AM
Have a shell script check for a file to exist before processing another file heprox Shell Programming and Scripting 3 11-14-2006 03:26 AM
Processing a text file TheCrunge UNIX for Dummies Questions & Answers 1 11-09-2005 11:47 AM

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

Join Date: Apr 2006
Posts: 99
File processing on perl

Hey everyone ...

I wanted to process the contents of a file, as in modify its contents. whats the best way to do it on perl? In more detail I hav to go through the contents of the file, match patterns n then modify the contents of the same file depending on the matching results. Any help is welcome.

Thanks n regards,
Garric
  #2 (permalink)  
Old 09-01-2006
mukundranjan mukundranjan is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 20
Hi,

This may help you.

Code:
1. open the file with fopen.
2. Read the contents line by line.
3. match the string with your pattern and repace accordingly.
4. Write line in another file.
5. remove new file with previous one.
  #3 (permalink)  
Old 09-01-2006
natesan81 natesan81 is offline
Registered User
  
 

Join Date: Aug 2006
Location: India
Posts: 2
Thumbs up Code

testfile.txt :

About Apple
Apple is a fruit
I like Apple Juice


Code

open(INFILE,"./testfile.txt")||die ("Cannot open testfile.txt");
open(OUTFILE,">./orange.txt")||die ("Cannot open orange.txt");
while($str=<INFILE>)
{
$str =~ s/Apple/Orange/g;
print OUTFILE $str;
}
close(INFILE);
close(OUTFILE);

Orange.txt


About Orange
Orange is a fruit
I like Orange Juice
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 11:02 PM.


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