10
rated 0 times
[
10]
[
0]
/ answers: 1 / hits: 5514
/ 1 Year ago, sun, march 26, 2023, 9:31:40
In a peculiar case I needed some of my text files to append with line number at the end. How to achieve this?
More From » text-processing
In a peculiar case I needed some of my text files to append with line number at the end. How to achieve this?
The awk
program stores the current line in variable $0
and the record number ("line number") in NR
. This command will print the lines with a line number appended:
awk '{ print $0, NR }' yourfile.txt
For prepending line numbers, there also exist the nl
command ("number lines of files"):
nl yourfile.txt