Closed apcamargo closed 1 year ago
Hi @apcamargo ,
I managed to do this with awk
and tac
(inspired from "awk Solution" of this answer : https://unix.stackexchange.com/a/139099)
==> test.csv <==
id,age,gender
1,39,M
2,25,M
3,36,F
4,45,F
tac test.csv | awk -v nbr=2 'NR<=nbr { prev=$0; print } END { if($0!=prev){print} }' | tac
id age gender
-- --- ------
3 36 F
4 45 F
N
last rows" in your question <--> nbr
awk variable definedprev=$0
in above cmd) and test for equality before printing last line
=> To avoid double printting header if nbr > nb_records
Hope this helps ! Have a nice day, Felix.
Thank you @tetedange13
As far as I know, there's no way to easily inspect the last
N
records of a.csv
file in a way that includes the header. I assume this could be achieved by reading the first line (the header) and skip to the lastN
lines of the file.