Display line number in head and tail command like `cat -n`
86
What about head and tail command? Is there any option to view the line number in head and tail without using
cat -n
and pipe the output to head or tail?
No; the current versions of head and tail do not have any way to add line numbers to the output themselves.
Author by
asker
Updated on September 18, 2022Comments
-
asker almost 2 years
I'm trying to get the key of these json objects in order to create a new object with extra filed to create table headers in a React app. JSON data:
let example = [ { id: 1, city: 'New York', }, { id: 2, city: 'Paris', }, ]
The function:
getKeys() { return example.map((key) => { return { cityName: key, // gets the whole array capital: false, }; }); }
I tries
Object.keys( example);
, it returns integers; 0, 1. How can I get the keys in this case? Thanks.-
Kusalananda about 5 years
-n
is the option for selecting the number of lines that you'd wanthead
ortail
to return.
-
-
Kusalananda about 5 yearsThere's nothing stopping the user from using
head file | cat -n
though. -
Jeff Schaller about 5 yearsYes, I was afraid I was being too brief; I was responding directly to the "can head or tail number lines directly?"