How to Read a File From the Command Line

14 Answers 14

answered Jun 20, 2013 at 15:21

ii

  • How is this like to tail -f? tail -f loops forever. How did you replicate the -f of it?

    January 17, 2018 at 10:16

  • This doesnt respond the question. Not sure why its rated so high. OP was looking for 2 things - a windows culling to cat, and an alternative to tail -f. If you're going to install the GNU utilities for windows, yous tin can then employ those things.

    Apr 15, 2019 at 14:thirty

We tin use the 'type' command to see file contents in cmd.

Example -

                type abc.txt                              

More information can exist found Hither.

answered Dec 25, 2015 at i:22

1

  • I like this answer considering information technology'southward non interactive. more shows N screens at a time that y'all have to click through

    Dec six, 2017 at 16:54

I don't think there is a built-in 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 current window. Peradventure this has params you lot tin can use...

There is a similar question here: CMD.EXE batch script to display concluding ten lines from a txt file And then at that place is a "more" control to display a file from the given line, or you tin employ the GNU Utilities for Win32 what bryanph suggested in his link.

answered Jun 20, 2013 at 15:24

0

Y'all can use the 'more than' command to come across the content of the file:

                more filename.txt                              

answered Jun 5, 2017 at nineteen:12

i

  • Welcome to StackOverflow and thanks for trying to help. Please explicate how the windows version of more can be used to automatically see newly arriving lines in a text file. That would make your respond more direct chronicle to OPs question, i.e. demonstrate the "tail -f"-compatibility OP wants.

    Jun five, 2017 at 19:59

To show content of a file:

type file.txt - cmd

true cat file.txt - bash/powershell

answered April 20, 2021 at ii:28

Using a single PowerShell command to retrieve the file ending:

                powershell -nologo "& "Become-Content -Await c:\logFile.log -Tail 10"                              

Information technology applies to PowerShell 3.0 and newer.

Another option is to create a file called TAIL.CMD with this code:

                powershell -nologo "& "Get-Content -Wait %1 -Tail %2"                              

answered Feb 17, 2016 at 12:59

1

  • It works, only it'southward besides irksome, equally PowerShell may accept two or iii seconds to beginning.

    Jun 21, 2020 at 20:35

To do this, you can use Microsoft'southward more advanced command-line shell called "Windows PowerShell." Information technology should come standard on the latest versions of Windows, simply you tin download information technology from Microsoft if you don't already have it installed.

To get the last five lines in the text file simply read the file using Get-Content, and so take Select-Object pick out the last five items/lines for y'all:

                Become-Content c:\scripts\test.txt | Select-Object -last five                              

Source: Using the Get-Content Cmdlet

answered May eighteen, 2016 at 18:l

1

  • @Eyal 's respond is more fitting being called from the cmd, and the code is improve using Tail than pipe into Select-Object. Y'all tin't exercise -Await while doing Select Object equally well. This is not what the OP is requesting.

    Jan 17, 2018 at 10:30

If you desire it to display the content of the file alive, and update when the file is altered, just use this script:

                @echo off :beginning cls type myfile.txt goto start                              

That will repeat 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 xi, 2018 at twenty:57

Y'all can practice that in some methods:

Ane is the blazon control: type filename Some other is the more control: more than filename With more you tin can also do that: type filename | more

The final option is using a for for /f "usebackq delims=" %%A in (filename) do (repeat.%%A) This will get for each line and display information technology'south content. This is an equivalent of the blazon command, but it'due south 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

There is no built in option available with Windows. To constantly monitor logs y'all can apply this free application BareTailPro.

answered Jun 20, 2013 at 15:21

answered Feb 8, 2016 at 13:22

1

  • Link just answers should be posted as comments

    February viii, 2016 at 13:44

If you lot want to brandish for example all .config (or .ini) file proper name and file content into one doctor for user reference (and past this I mean user not knowing shell command i.e. 95% of them), you can try this :

                FORFILES /1000 *myFile.ini /C "cmd /c echo File name : @file >> %temp%\stdout.txt && blazon @path >> %temp%\stdout.txt && echo. >> %temp%\stdout.txt" | type %temp%\stdout.txt                              

Caption :

  • ForFiles : loop on a directory (and child, etc) each file meeting criteria
    • able to return the current file name beingness procedure (@file)
    • able to return the total path file beingness process (@path)
  • Type : Output the file content

Ps : The concluding pipe control is pointing the %temp% file and output the amass content. If you wish to copy/paste in some documentation, just open the stdout.txt file in textpad.

Anic17

623 four silver badges 14 bronze badges

answered Nov 19, 2019 at 18:25

0

You tin utilize either more than filename.[extension] or type filename.[extension]

enter image description here

StupidWolf

40.4k 17 gold badges 29 silver badges 58 bronze badges

answered Jun 4, 2021 at half dozen:12

2

  • try to give a more detailed explanation, and please update your prototype to load directly in StackOverflow

    Jun 4, 2021 at 9:36

  • both commands were suggested several times before (and don't fifty-fifty answer the question). And then this respond adds nothing just noise.

    Jun 4, 2021 at 9:40

                tail -3 d:\text_file.txt  tail -1 d:\text_file.txt                              

I assume this was added to Windows cmd.exe at some betoken.

Ian

29.1k 18 golden badges 64 silver badges 102 bronze badges

answered January 29, 2016 at 14:14

2

  • no, tail is still non a standard windows command. Normally it's role of an addon like cygwin, GNU or others.

    Jan 29, 2016 at fourteen:twenty

  • This is non a good answer, you are only saying that this has been implemented into Windows, but no, please check your information before answering.

    Jun fourteen, 2020 at 16:03

Not the respond you're looking for? Browse other questions tagged cmd or enquire your own question.

kelleyobtionve.blogspot.com

Source: https://stackoverflow.com/questions/17217476/how-do-i-display-a-text-file-content-in-cmd

0 Response to "How to Read a File From the Command Line"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel