Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a file say "f1" with ten line and I found that line no 7 has been added or say deleted so how can i get that line into another file can any1 let me know please Thanks! can mail me on my mail id gauravbit70@yahoo.com

Replies are listed 'Best First'.
Re: find added or deleted line in a file
by Anonymous Monk on Apr 21, 2011 at 08:44 UTC
    I have a file say "f1" with ten line and I found that line no 7 has been added or say deleted so how can i get that line into another file can any1 let me know please Thanks!

    Let me understand, you have sucessfully opened a file, read lines, and found that the 7th line has been added or deleted, but you don't know how to get that line into another file?

    That sounds impossible, have you understood perlintro?

Re: find added or deleted line in a file
by pajout (Curate) on Apr 21, 2011 at 08:31 UTC
    Please, show us your code, monks like to advice, but not like to work just for work.
Re: find added or deleted line in a file
by anonymized user 468275 (Curate) on Apr 21, 2011 at 09:47 UTC
    Extract line 7 from fred to bert
    perl -ne '$fh = ( $.==7 ? STDERR : STDOUT ); print $fh $_;' < fred >tm +p 2>bert; mv tmp fred
    Insert at line 7 in fred from another file bert
    perl -ne '$.==7 and system("cat bert");print $_;' < fred >tmp; mv tmp +fred

    One world, one people