The UNIX and Linux Forums  

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
Inserting file into another file at a specified line number Rajendra_1510 Shell Programming and Scripting 4 10-20-2008 01:52 AM
inserting a new line in a file gelitini Shell Programming and Scripting 1 07-07-2008 01:22 PM
comparing and inserting common line in other file namishtiwari Shell Programming and Scripting 2 03-25-2008 08:09 AM
Inserting New Line in File using Sed ?? Mary_xxx Shell Programming and Scripting 4 02-27-2008 04:50 PM
perl/mail - inserting file text in message body thumper Shell Programming and Scripting 2 01-28-2008 03:29 PM

 
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
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 01-19-2009
portalfaq portalfaq is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 1
Need Help in Inserting a new line in a file using PERL

I need a perl script to find and replace a specific pattern in a file to a new line.

BAsically I have a single line data in a file with 10 mb to 200 MB. I want to put a new line based on a specific pattern to open the file in Excel / Access.

Following is the sample data in a file

*PAABCD *BA1Z8345 SAMPLE *FA00 *PA1Z TEST *FA00 DATA FROM THE LAB *BA1Z1000 research from the customer is endless

I want the out put to look like this

*BA1Z8345 SAMPLE *FA00 *PA1Z TEST *FA00 DATA FROM THE LAB
*BA1Z1000 research from the customer is endless


I tried the following perl script. It did not work properly. i need some help.

Code:
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
my $startdir = '/home/mydir/';
my $find = '/*BA1Z';
my $replace = '\n*BA1Z';
my $doctype = 'txt';
print qq~Finding "$find" and replacing it with "$replace"\n~;
find(
 sub{
   return unless (/\.$doctype$/i);
   local @ARGV = $_;
   local $^I = '.bac';
   while( <> ){
      if( s/$find/$replace/ig ) { 
      print;
   }
  else {
      print;
  }
 }
}, $startdir);
print "Finished";


Last edited by otheus; 01-30-2009 at 07:46 AM.. Reason: code tags added, formatting changed
 

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 08:47 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