Questions tagged [unix-head]

The Unix `head` command displays the leading lines of a file.

head is a unix command which displays the first lines of a file. It's counterpart which displays the last lines is tail ().

Example: head -n 10 file will output first 10 lines of file.

55 questions
0
votes
0 answers

How does a program "know" to terminate early when its output is piped to head?

Say I need to run a UNIX command-line program on some big file. If I want to see a bit of the output, I can pipe the output to head: $ cat big_file.txt | head For cat and many similar programs, this command runs extremely fast. Since only the first…
Paul
  • 3,321
  • 1
  • 33
  • 42
0
votes
2 answers

How do I copy the beginning of multiple files in Linux?

I want to copy a bunch of files (*.txt) from one directory to another in Ubuntu. I want to reduce them in size, so I am using head to get the first 100 lines of each. I want the new files to keep their original names but be in the subdirectory…
schoon
  • 2,858
  • 3
  • 46
  • 78
0
votes
4 answers

UNIX programming: Head command

so I'm working on this assignment and I am having trouble with the head command in Unix. Our assignment is to find all of the .txt files within a directory and display the first line of text from each one the output should look like this:…
user4058875
0
votes
2 answers

Remove lines from head and tail of multiple text files and merge

I have multiple text files with different data, but same header & bottom text. I have to remove the header and tail text and merge them into one output file. Any one liner with decent speed would be good. All of the file names Start with the name…
Muz
  • 73
  • 1
  • 8
0
votes
1 answer

Why is this pipe not terminated

Topic Why is this pipe terminated? explains, why a pipe may prematurely be closed by 'head': find / | head So why is the following pipe not closed by 'head'? find / -exec zgrep -l 'a' {} \; | head using grep instead of zgrep produces lots of…
Henning
  • 1,289
  • 2
  • 11
  • 25
0
votes
1 answer

Dealing with cat and head in a bash loop

I am trying to add two lines of text from one file to the beginning of a bunch of other files by using a for loop in the bash command line. I tried this in the command line: $for i in *.txt; do head -2 ../../041_R_def_c.txt > X; cat i >> X; \mv X i;…
0
votes
2 answers

Converting head program to tail C

I just got a semi function head program running and I need help making it into a tail program where it will display x number of lines at the end of the file. Here is my head code. I'm having trouble thinking of how to get the counter to read the…
V Or
  • 141
  • 5
  • 16
-1
votes
1 answer

Passing the most recent file in a directory to a program

What would be the correct way to do the following: $ ls -t | head -n1 | vim - Currently, this will read the 'filename' into vim, but I'm looking at actual open that filename that's passed to it as a string. How would this be done? Without opening…
samuelbrody1249
  • 4,379
  • 1
  • 15
  • 58
-1
votes
3 answers

head and tail on Unix

My second homework assignment asks for us to write a command in Unix or Linux to extract certain sections of multiple files using head and tail. I'm not understanding how to go about this. Here is the question: (5 points) Using head and tail, write…
N00b123
  • 11
  • 1
  • 2
-2
votes
1 answer

How to print lines between 2 values using tail & head and pipe?

For example:how can I print specific lines of a .txt file between line 5 and line 8 using only tail and head
lambozsolty
  • 81
  • 10
1 2 3
4