Code Comments
Programming Forum and web based access to our favorite programming groups.
davide moro wrote:
> Today I made this bash-script, can you help me to translate it to awk-code
?
> Its prototype is:
> ls -l | ./script 1 7 9 12
> It prints the 1st, 7th, 9th and 12th record of any stream of characters (f
or
> example: ls -l, cat file1, ecc)
<snip>
> AWK:
> example: ls -l | ./script.awk 1 7 10
> I have this idea
> {
> if (count == ???????)
> print;
> count++;
> }
>
> but I don't know what I should write instead of ?????.
> Can anyone help me?
Here's one way:
lineNrs="1 7 10"
awk -v lineNrString="$lineNrs" 'BEGIN {
split(lineNrString,i2LNs)
for (i in i2LNs) lineNrs[i2LNs[i]] = i
}
NR in lineNrs { print }'
Regards,
Ed.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.