Welcome to the monastery. From the task description I'd say perl is very well suited. I'll give you an example for a program that roughly does what you describe
Or you could do this in a perl oneliner (which will change the original file):#!/usr/bin/perl use warnings; use strict; my $filename = "whateveryourfileiscalled.txt"; my $newfile = "whateveryouwantthechangedfiletobecalled.txt"; open (my $rfh,"<",$filename) or die "Can't open file $filename : $!"; open (my $wfh,">",$newfile) or die "Can't open file $newfile : $!"; while (my $line = <$rfh>) { if ($line =~ m/^HEADER/) { chomp $line; my $number = 42; # change to whatever number you want to use $line .= $number."\n"; } if ($line =~ m/^REMARK/) { print {$wfh} "Extra line\n" # Change to whatever extra line yo +u want } print {$wfh} $line; } close $rfh or die "Can't close $filename : $!"; close $wfh or die "Can't close $newfile : $!";
perl -pi -e 'chomp;s/^(HEADER.*)$/${1}42/;s/^(REMARK.*)$/Extra line\n$ +1/;$_.="\n"' whateveryourfileiscalled.txt
In reply to Re: Newbie: uses/limits of perl in editing files
by tirwhan
in thread Newbie: uses/limits of perl in editing files
by wherethewild
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |