Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

find added or deleted line in a file

by Anonymous Monk
on Apr 21, 2011 at 07:14 UTC ( [id://900486]=perlquestion: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

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

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

    No recent polls found