Friday, September 29, 2023
10
rated 0 times [  10] [ 0]  / answers: 1 / hits: 5493  / 7 Months 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

 Answers
0

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

[#21943] Tuesday, March 28, 2023, 7 Months  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
raldership

Total Points: 222
Total Questions: 115
Total Answers: 124

Location: North Korea
Member since Fri, Nov 4, 2022
12 Months ago
;