Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i get the first line of the output for given command in dos

Tags:

dos

I need to get the very first line of the command line output not all line, For example if i give

             C:\Temp> dir

I need display the Very first line only like,

             11/15/2012  06:58 PM    <DIR>          .

How can i get this ?

Thanks in advance.

like image 468
user1553605 Avatar asked Nov 28 '12 08:11

user1553605


People also ask

How do I read the first line of a file in CMD?

How do I print the first 5 lines of a file? To look at the first few lines of a file, type head filename, where filename is the name of the file you want to look at, and then press <Enter>. By default, head shows you the first 10 lines of a file.

How do you get the first line of a shell?

Adding #!/bin/bash as the first line of your script, tells the OS to invoke the specified shell to execute the commands that follow in the script.

How do you go back a line in CMD?

When you want to go back, type cd - and you will be back where you started.

What is start command in DOS?

In computing, start is a command of the IBM OS/2, Microsoft Windows and ReactOS command-line interpreter cmd.exe (and some versions of COMMAND.COM) to start programs or batch files or to open files or directories using the default program.


1 Answers

One approach to get the first line of output for a given command is to execute the command in a FOR loop, then break out of the loop after the first line.

@ECHO OFF

SET COMMAND=dir
FOR /F "delims=" %%A IN ('%COMMAND%') DO (
    SET TEMPVAR=%%A
    GOTO :Print 
)

:Print
ECHO %TEMPVAR%
like image 189
RB. Avatar answered Sep 28 '22 04:09

RB.