![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
| Display Modes | Rate This Thread |
|
|