4
1
In Linux, I can easily view any files with line number next to it with cat -n
command.
sh-4.4$ cat test
line 1
line 2
line 3
sh-4.4$
sh-4.4$ cat test -n
1 line 1
2 line 2
3 line 3
sh-4.4$
What about Windows? Is there any similar command producing similar output?
type
is one of the windows command to view content of the file.
C:\>type test.txt
line 1
line 2
line 3
C:\>
However, there is no -n
option in it.
C:\>type /?
Displays the contents of a text file or files.
TYPE [drive:][path]filename
C:\>
This is what I'm expecting in Windows
C:\>(windows command to view and print line number) test.txt
1 line 1
2 line 2
3 line 3
C:\>
1It works very well with Powershell.
PS C:\> $i = 1; cat .\test.txt | % {$i++;"$($i-1)
t $"} 1 line 1 2 line 2 3 line 3 PS C:> PS C:> $i = 1; get-content .\test.txt | % {$i++;"$($i-1) `t $"} 1 line 1 2 line 2 3 line 3 PS C:>` – Sabrina – 2018-03-10T07:19:32.0672@Sabrina Glad it helped. Although, simply installing a 'cat' program might be more convenient in the long run – Keltari – 2018-03-10T07:28:10.647