Quantcast
Channel: Write a program that read from a file and print the line with line number - Unix & Linux Stack Exchange
Browsing latest articles
Browse All 4 View Live

Answer by jai_s for Write a program that read from a file and print the line...

You could use nl too -- nl -s. -ba file 1.This is the first line 2.This is the second line 3.This is the third line 4. 5.This was a blank line

View Article



Answer by Rui F Ribeiro for Write a program that read from a file and print...

Using awk it is enough to do: awk ' { print NR". " $1 } ' < file.txt $1 is the string of text in the input, and NR an internal awk variable that tracks the current line number (e.g. Number of...

View Article

Answer by heemayl for Write a program that read from a file and print the...

Using a short while construct: % i=1; while IFS= read -r line; do printf '%s. %s\n' "$i" "$line"; ((i++)); done <file.txt 1. This is the first line 2. This is the second line 3. This is the third...

View Article

Write a program that read from a file and print the line with line number

I need to write a program that will read line from a file and then output the lines. So the files contains this: This is the first line This is the second line This is the third line This was a blank...

View Article
Browsing latest articles
Browse All 4 View Live




Latest Images