2005-06-30 Software

Somebody asked on ​#linux.ch:

21:03 < tom> 21:01:01 < tom> tarzeau: nein. ich will z.b. "proggie file.txt 123
             456 789" und er gibt mir dann die zeilen 123, 456 und 789 der
             datei file.txt aus

A few minutes later I suggested:

$file = shift or die "No file";
open F, $file or die $!;
while (<F>) {
  $count++;
  if (grep /^$count$/, @ARGV) {
    print "$count: $_";
  }
}

Tested:

21:09 < kensanata> aschroeder@thinkmo:~$ perl test.pl test.pl 1 3
21:09 < kensanata> 1: $file = shift or die "No file";
21:09 < kensanata> 3: while (<F>) {

​#Software

Comments

(Please contact me if you want to remove your comment.)

just for me to learn some shell scripting:

#!/bin/sh
file=${1:?"No File"};shift
for linenumber in $@; do
 echo -n "$linenumber: "
 sed -n $linenumber' p' < $file
done

– PierreGaston 2005-06-30 20:15 UTC