FWIW, when I do 'cvs rlog -R .' it asserts:

cvs: recurse.c:642: do_recursion: Assertion `strstr (repository, "/./") == ((void *)0)' failed.
cvs [rlog aborted]: received abort signal

I'm using 1.11.19

John Smith wrote:
I tried:
cvs rlog -R . | grep '^cvs rlog:' | awk '{print $NF}'
but the grep returns 0 lines because everyline of cvs rlog -R . starts
with cvs rlog.

No, every line of 'cvs rlog -R' does not start with 'cvs rlog'. Only the directory lines start with 'cvs rlog', and they are written to stderr, not stdout. So, the grep in your pipe above will find nothing in stdout that matches the pattern, and so pass nothing on to awk.

This might work better (assuming you're using bash/ksh)

cvs rlog -R . 2>&1 >/dev/null | awk '{print $NF}'

or this, if you really want to use grep

cvs rlog -R . 2>&1 | grep '^cvs rlog:' | awk '{print $NF}'


furthermore, I don't think $NF returns the # of fields as it is
supposed to in awk.

I don't know that much about awk, but if you think that you're wrong.

|A|B|C|D|

head -n 1 output.txt | awk -F"|" '{print $NF}'

prints a blank line.

the following prints "B":
head -n 1 output.txt | awk -F"|" '{print $3}'
B

Why?

Well the 'System Variables' section of O'Reilly's 'Sed & Awk' book says that NF is the number of fields, and $NF is the contents of the last field. Experimenting with this I get:

% echo '|A|B|C|D|' | awk -F"|" '{print NF}'
6
% echo '|A|B|C|D|' | awk -F"|" '{print $NF}'


which is exactly what the book says I should get. The reason my second example (and your first one) prints a blank line is because the last field (the one following the last '|') is empty.

OTOH, according to the 'Records and Fields' section of the same book the '$' is the field operator, where $n refers to field n. So $NF in these examples is the same as $6 (since NF is 6.) The reason that your second example returns a 'B' is that the third field field (the one to the right of the second '|') is 'B'. (The first field, to the left of the first '|', is empty.)

% echo '|A|B|C|D|' | awk -F"|" '{print $3}'
B
% echo '|A|B|C|D|' | awk -F"|" '{print $1}'


--
----------------
Mark E. Hamilton
Orion International Technologies, Inc.
Sandia National Laboratory, NM.
505-844-7666



_______________________________________________
Info-cvs mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/info-cvs

Reply via email to