Score:0

How can I use bat command as an alternative to tail command?

th flag

I love the syntax highlighting of cat. So I want to use it as an alternative to tail command. But I cannot find a generic way to accomplish this. But I can use this command as an alternative to tail if I know the line numbers of the file.

e.g: if a file named test.log contains 90 lines, I can use the following command to print the last 10 lines.

batcat --line-range "80:" test.log

But I can't do the same if I don't know the line numbers of file. Is there any other way?

chili555 avatar
cn flag
Please try: `cat test.log | tail -n10` Welcome to Ask Ubuntu.
Score:0
st flag

tail -n10 is the proper shortest answer, but to do it by running batcat:

batcat --line-range $(expr $(wc -l /etc/hosts | cut -d" " -f 1) - 1): /etc/hosts

You just change the -1 to whatever number of lines you want -1, so if you want 10 you set it to -9. The ":" in batcat doesn't take negative number, so no shortcut.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.