Is there any equivalent of head from Linux in cmd?
If you mean plain old cmd, then no.
But there is one in the new Windows Powershell (it is included in every version of Windows after Vista and I believe you can also download it for XP). Launch powershell (Accessories => Windows Powershell) and use the Select command, for example:


Code:
PS > dir | Select -First 5


Will you give you the first 5 lines of the output of dir command.
i use cmd, so i wrote a head command for it:

Code:

#include <stdio.h>
#include <stdlib.h>

main( int argc, char * argv[])
{
int i, p, ch,x;
FILE *fp;

   
   if (argc != 2 && argc != 3)
    {
       printf("Erro- nr de argumentos\n");
       return;
    }



    if (argc == 3)
     if (fopen(argv[2], "r") && atoi(argv[1]))
     {
       i = atoi(argv[1]);
       fp = fopen(argv[2], "r");
     }
       else
      {
          printf("Erro 3\n");
          return;
      }
    
     if (argc == 2)
    
     if (fopen(argv[1], "r"))
     {
         fp = fopen(argv[1], "r");
         i = 10;
      
     }
      
    
       else
      {
          printf("Erro 3\n");
          return;
      }
     
     
     
     for(p=0; (ch=fgetc(fp))!= EOF && p<i ; )
      {
      if (ch=='\n')
       ++p;
       putchar(ch);
      }
     
}


If I put this in the cmd file, will I be able to use/call it from whatever path I'm using? If yes, where is the cmd folder?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement