Questions tagged [head]

head is a program on Unix and Unix-like systems used to display the beginning of a text file or piped data.

32 questions
93
votes
6 answers

Opposite of tail: all lines except the last n lines

How can I discard the last n lines of a file with a unix command line filter? That would be sort of the opposite of tail: tail discards the first n lines but pipes the rest through, but I want the command to pipe everything through except the last n…
29
votes
2 answers

tail/head all line except X last/first Lines

for example i have this file : cat myfile 1 2 3 4 5 i want to print all lines except first 2 line . output should be like this : tail -n $(( $(wc -l myfile | awk '{print $1}') - 2 )) myfile 3 4 5 Yes , out put is correct. but there is a problem ,…
network
  • 401
  • 1
  • 4
  • 4
24
votes
4 answers

Using 'head' or 'tail' on HUGE text file - 19 GB

I have a problem with viewing chunks of a very large text file. This file, approximately 19 GB, is obviously too big to view by any traditional means. I have tried head 1 and tail 1 (head -n 1 and tail -n 1) with both commands piped together in…
nicorellius
  • 6,815
15
votes
7 answers

Creating a large file of random bytes quickly

I want to create a large file ~10G filled with zeros and random values. I have tried using: dd if=/dev/urandom of=10Gfile bs=5G count=10 it creates a file of about 2Gb and exits with a exit status 0. I fail to understand why? I also tried creating…
egeek
  • 271
8
votes
3 answers

How to echo only 1st line from 'curl' command output?

I'm trying to get only first line of the curl command output. (Sorry if this is confusing) Let's say, for an instance, i run simply: # curl http://localhost .. .. What…
6
votes
2 answers

Stopping after first line of output

I try to do the following in a Bash script: run a command (such as tail -f log_file), wait until a specific output arrives, then stop the command, and go on with the script. I tried the following, but it didn't work: tail -f log_file | grep…
petersohn
  • 2,708
5
votes
1 answer

How to easily break up a text file into pieces smaller than a threshold?

I have some text files that are 100 to 300 MB in length that I want to view in Emacs, but my Emacs gets into some performance issues opening and traversing such large files. Therefore, I'm looking for an easy utility to split a file up into…
WilliamKF
  • 8,058
3
votes
1 answer

Head on very large files

I have 2 very big files (27G and 40G), which are output of dd command on a failing hard drive. I wanted to compare the first bytes to see if the 27G bytes is the begining/substring of the 40G. I wanted to use head command. Since these files are…
Thibault
  • 167
3
votes
2 answers

Unix tool to output first n characters in an UTF-8 encoded file

I want to print the first 1000 characters in an UTF-8 encoded file. I know that the head tool can print the first n bytes of a file, but it may cut a character in the middle so that I get garbled output at the end. I can write a awk program to do…
3
votes
2 answers

How to copy head of files to another folder, keeping tree structure?

I have a bunch of huge files (4GB+ each) with the same extension in a directory structure in a network drive, but am only interested in the first few bytes of each, so I'd like to copy them all to my local drive, with the same filenames and…
user2986
  • 133
3
votes
3 answers

How to grab a random section in the middle of a huge file?

I have a huge log file of around 3.5 GB and would like to sample random sections in the middle of say 10 MB for the purpose of debugging what my application is doing. I could use head or tail commands to get the beginning or end of the file, how can…
WilliamKF
  • 8,058
2
votes
1 answer

How to resolve conflicts when two binaries have the same name

Running OS X (10.9), I have a program called 'HEAD' in /Applications/XAMPP/xamppfiles/bin/, which is related to libwww-perl. The OS also has an unrelated program called 'head' in /usr/bin/ Since the filesystem is not case-sensitive, and both of…
Elliott B
  • 1,347
  • 5
  • 17
  • 44
2
votes
1 answer

What's the best way to view lines X through Y of a large file?

I have a very large text file and I want to view, say, lines 2000 through 2010 (with the line numbers included) I know one sort of roundabout way of getting there: sc -l [file] cat -n [file] | tail -n [previous result - 2000] | head -n 10 But it…
Dan Tao
  • 1,109
2
votes
1 answer

How to solve "Broken Pipe" error when using awk with head

I'm getting broken pipe errors from a command that does something like: ls -tr1 /a/path | awk -F '\n' -vpath=/prepend/path/ '{print path$1}' | head -n 50 Essentially I want to list (with absolute path) the oldest X files in a directory. What seems…
Jon
  • 21
1
vote
1 answer

How to grep for line numbers in a binary file?

I'm on Centos 5 Linux and using GNU grep v2.5.1 and looking at a 36GB log file. It is huge and I need to find around a million lines starting from the occurrence of a string 6307459 in the log file and view it in emacs. I'm using grep to find the…
WilliamKF
  • 8,058
1
2 3