On Sat, 23 Oct 1999 19:11:25 +0200,
>I have an ascii file that looks similar to the following one:
>Jaeck Roger male
>Jaeck Marco male
>Jaeck Rene male
>Jaeck Ruth female
>and so on
>how can I write a little shell function with a parameter, for example:
>select_line file [paramter]
>for example: select familiy 3
>that returns
>Jaeck Rene male
As usual, there are many ways to do this:
sed -n '3 p' family
-n = suppress default output
3 p = in line 3, print
sed -n '3 p; 3 q' family
A faster version which doesn't scan the rest of the file.
3 q = in line 3, quit
awk 'NR == 3' family
awk 'NR == 3 { print }' family
NR = ordinal number of the current record
awk 'NR == 3 { print; exit }' family
A faster version which doesn't scan the rest of the file.
perl -ne 'print if $.==3' family
perl -ne 'if($.==3){ print }' family
$. = current line number
perl -ne 'if($.==3){ print; exit }' family
A faster version which doesn't scan the rest of the file.
tail +3 family | head -1
Skip first two lines, then only select first of result.
This should be enough for a starter ... :)
Regards,
Martin
--
PGP KeyID=0xE8EF4F75 FiPr=5244 5EF3 B0B1 3826 E4EC 8058 7B31 3AD7