How to Read a Text File From Command Line
14 Answers 14
answered Jun xx, 2013 at 15:21
limcy_at_miplimcy_at_mip
4,455 1 aureate badge xiv silver badges two bronze badges
2
We can utilise the 'blazon' command to see file contents in cmd.
Instance -
type abc.txt More information can be found Hither.
answered Dec 25, 2015 at 1:22
Anmol SarafAnmol Saraf
14k 9 gold badges 48 silver badges 59 bronze badges
i
-
I similar this answer considering it's non interactive.
more thanshows N screens at a time that you lot accept to click throughDecember half dozen, 2017 at 16:54
I don't think there is a born function for that
xxxx.txt > con This opens the files in the default text editor in windows...
type xxxx.txt This displays the file in the electric current window. Perhaps this has params yous can utilize...
There is a similar question here: CMD.EXE batch script to display last 10 lines from a txt file And so at that place is a "more" command to display a file from the given line, or you can employ the GNU Utilities for Win32 what bryanph suggested in his link.
answered Jun twenty, 2013 at fifteen:24
inf3rnoinf3rno
22k 10 gold badges 104 silver badges 181 bronze badges
0
Yous can use the 'more than' control to see the content of the file:
more filename.txt
answered Jun v, 2017 at xix:12
one
-
Welcome to StackOverflow and thanks for trying to help. Please explicate how the windows version of more can be used to automatically run across newly arriving lines in a text file. That would make your answer more straight chronicle to OPs question, i.e. demonstrate the "tail -f"-compatibility OP wants.
Jun five, 2017 at 19:59
To prove content of a file:
type file.txt - cmd
true cat file.txt - bash/powershell
answered Apr 20, 2021 at 2:28
LaurentBajLaurentBaj
183 1 silver badge nine bronze badges
Using a single PowerShell command to retrieve the file ending:
powershell -nologo "& "Get-Content -Wait c:\logFile.log -Tail 10" Information technology applies to PowerShell three.0 and newer.
Some other choice is to create a file called TAIL.CMD with this lawmaking:
powershell -nologo "& "Get-Content -Await %one -Tail %two"
answered February 17, 2016 at 12:59
EyalEyal
161 1 silver badge 9 bronze badges
1
-
It works, but it's too slow, as PowerShell may have two or three seconds to starting time.
Jun 21, 2020 at 20:35
To practice this, you can utilise Microsoft's more avant-garde command-line beat out called "Windows PowerShell." It should come standard on the latest versions of Windows, but you can download it from Microsoft if you lot don't already have it installed.
To get the last five lines in the text file simply read the file using Go-Content, then have Select-Object selection out the final five items/lines for yous:
Get-Content c:\scripts\exam.txt | Select-Object -last 5 Source: Using the Get-Content Cmdlet
answered May 18, 2016 at 18:50
ane
-
@Eyal 'southward answer is more fitting beingness called from the cmd, and the code is better using Tail than piping into Select-Object. You can't exercise -Wait while doing Select Object equally well. This is non what the OP is requesting.
Jan 17, 2018 at 10:30
If you want it to display the content of the file live, and update when the file is altered, just use this script:
@echo off :showtime cls type myfile.txt goto showtime That will echo forever until you lot close the cmd window.
answered Mar 11, 2017 at 3:08
1
-
This does not replicate the functionality of tail.
Mar 11, 2018 at 20:57
You can do that in some methods:
I is the type command: type filename Another is the more command: more filename With more yous can too do that: type filename | more than
The terminal option is using a for for /f "usebackq delims=" %%A in (filename) do (echo.%%A) This will become for each line and display it's content. This is an equivalent of the type control, but information technology's another method of reading the content.
If you are request what to use, use the more command every bit it will make a pause.
answered Jun fourteen, 2020 at 16:01
Anic17Anic17
623 4 silver badges 14 statuary badges
There is no congenital in choice available with Windows. To constantly monitor logs you can utilise this gratis awarding BareTailPro.
answered Jun xx, 2013 at 15:21
SudheejSudheej
1,676 6 gold badges 23 silver badges 51 bronze badges
answered February 8, 2016 at thirteen:22
noninoni
105 1 silver bluecoat 8 bronze badges
1
-
Link only answers should be posted every bit comments
February viii, 2016 at 13:44
If yous desire to display for example all .config (or .ini) file name and file content into one physician for user reference (and by this I hateful user not knowing beat command i.eastward. 95% of them), you tin try this :
FORFILES /M *myFile.ini /C "cmd /c echo File proper noun : @file >> %temp%\stdout.txt && type @path >> %temp%\stdout.txt && repeat. >> %temp%\stdout.txt" | blazon %temp%\stdout.txt Explanation :
- ForFiles : loop on a directory (and kid, etc) each file meeting criteria
- able to return the current file name being procedure (@file)
- able to return the total path file being process (@path)
- Type : Output the file content
Ps : The last pipe command is pointing the %temp% file and output the aggregate content. If y'all wish to copy/paste in some documentation, but open the stdout.txt file in textpad.
Anic17
623 iv argent badges xiv bronze badges
answered Nov 19, 2019 at 18:25
0
You can apply either more filename.[extension] or type filename.[extension]
StupidWolf
forty.4k 17 gilt badges 29 silvery badges 58 bronze badges
answered Jun iv, 2021 at 6:12
ii
-
attempt to give a more detailed explanation, and please update your image to load direct in StackOverflow
Jun 4, 2021 at nine:36
-
both commands were suggested several times before (and don't even answer the question). And then this answer adds nothing just racket.
Jun 4, 2021 at nine:xl
tail -3 d:\text_file.txt tail -1 d:\text_file.txt I presume this was added to Windows cmd.exe at some bespeak.
Ian
29.1k eighteen gold badges 64 silver badges 102 statuary badges
answered Jan 29, 2016 at fourteen:fourteen
2
-
no,
tailis still not a standard windows command. Usually it'south part of an addon like cygwin, GNU or others.Jan 29, 2016 at 14:20
-
This is not a expert reply, yous are just saying that this has been implemented into Windows, simply no, delight cheque your data before answering.
Jun fourteen, 2020 at 16:03
Non the answer you're looking for? Browse other questions tagged cmd or ask your own question.
Source: https://stackoverflow.com/questions/17217476/how-do-i-display-a-text-file-content-in-cmd
How is this similar to tail -f? tail -f loops forever. How did you replicate the -f of it?
January 17, 2018 at ten:16
This doesnt answer the question. Not certain why its rated so high. OP was looking for two things - a windows alternative to cat, and an alternative to tail -f. If you're going to install the GNU utilities for windows, you can and so use those things.
Apr 15, 2019 at fourteen:30