Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Replace specific lines specific range of characters.

by govindkailas (Acolyte)
on Apr 04, 2013 at 11:50 UTC ( [id://1026979]=perlquestion: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    die "usage: perl $0 file_nm line_nb col_start col_end replacement \n" 
    +unless @ARGV;
    die "Invalid number of arguments \nusage: perl $0 file_nm line_nb col_
    +start col_end replacement \n" if @ARGV ne 5;
    ...
    chomp ($replacement=`perl -ne "substr($content, $col_start, $col_end, 
    +$string);print $content"`); #get the replaced line
    #print "New content \n$content \n";
    `perl -pi -e "s/$content/$replacement/" $file_nm`; #now substitute the
    + whole line with the new replaced line
    
  2. or download this
    use File::Basename;
    die "usage: perl $0 file_nm line_nb pos_start-pos_end replacement \n" 
    +unless @ARGV;
    ...
    
    close(WRITE_HN);
    close(READ_HN);
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1026979]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2024-04-18 03:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found