Reputation: 67
I want to output the number of characters in each line in the txt file after printing the line. The awk script I am using is:
awk 'length($0)>19 END {print length($0)}' marks.txt
,
but it doesn't print the number of characters in each line. There is a 0 after printing the file content in the output, but this is not what I need. Could anyone point out what I did wrong? Thanks!
The content of the marks.txt file is:
1) Amit Physics 80
2) Rahul Maths 90
3) Shyam Biology 87
4) Kedar English 85
5) Hari History 89
The output is
1) Amit Physics 80
2) Rahul Maths 90
3) Shyam Biology 87
4) Kedar English 85
5) Hari History 89
0
Upvotes: 3
Views: 1411
Reputation: 4865
Using awk
awk '{print $0, length}' input.txt
1) Amit Physics 80 27
2) Rahul Maths 90 27
3) Shyam Biology 87 27
4) Kedar English 85 27
5) Hari History 89 27
Upvotes: 2