code_junkie

How can I extract a line or row?

Nov 11th, 2011
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. 1,julz,kath,shiela,angel
  2. 2,may,ann,janice,aika
  3. 3,christal,justine,kim
  4. 4,kris,allan,jc,mine
  5.  
  6. 3,christal,justine,kim
  7.  
  8. perl -ne 'if ($. == 3) {print;exit}' infile.txt
  9.  
  10. $ perl -ne'print if $. == 3' your_file.txt
  11.  
  12. $ perl -mTie::File -e'tie @lines, q(Tie::File), q(your_file.txt);
  13. > print $lines[2]'
  14.  
  15. perl -ne 'print if 3..3' <infile >outfile
  16.  
  17. perl -F, -nae 'print if $F[0] == 3' <infile >outfile # thanks for the comment doh!
  18.  
  19. use Tie::File;
  20. use Fcntl "O_RDONLY";
  21. tie my @line, "Tie::File", "yourfilename", mode => O_RDONLY
  22. or die "Couldn't open file: $!";
  23. print "The third line is ", $line[2];
  24.  
  25. open my $fh, '<', 'infile.txt';
  26. while (my $line = <$fh>) {
  27. print $line if i_want_this_line($line);
  28. }
  29.  
  30. open $fh, "myfile.txt";
  31. my @lines = <$fh>;
Add Comment
Please, Sign In to add comment