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.
31
questions
0
votes
1
answer
21
views
how to output only a specific known line number using cat or head/tail
I know how to use head or tail to output a certain number of lines, but how do I output only a specific line number(s)?
Something like:
head --only-line=73 <file>
0
votes
2
answers
295
views
How to get SHA1 of first 4096 bytes of an mp4 file or stream?
I am trying to use command line tools to match the hash value that Plex.app computes for movie files (apparently, it's an SHA1 hash of the first block (4k) of a movie instead of the entire movie).
I ...
1
vote
1
answer
140
views
get the top urls from the logs
I have a numbers of log files:
adsfs.demo.com_2022-07-11-0000-0001_cn.tgz
adsfs.demo.com_2022-07-11-0000-0002_cn.tgz
adsfs.demo.com_2022-07-11-0000-0003_cn.tgz
adsfs.demo.com_2022-07-11-0000-...
0
votes
1
answer
157
views
`openssl digest | head -c 10` gives strange results
I'm using salted hashes of some memorable words as login/pass for anonymous accounts and just now I've noticed that sometimes I get no result for my method and then I've discovered that it was not ...
0
votes
1
answer
63
views
Command Line Number Line Not In Sync
I'm playing around with the command line. For some reason when I try to grab lines 439 - 445 the output I am getting is lines 375 - 381 instead. I use the tail command to jump to line 439 then use the ...
0
votes
1
answer
293
views
Linux head/tail commands' man page does not show the '-LINES' argument
I have just read in a book that the command head -LINES displays the first LINES lines of a file. However, head's man page does not seem to reveal this is a legit argument. I'd like to know what I am ...
0
votes
1
answer
1k
views
How can I detect/remove special characters from this short text file?
This is the contents of a short text file created by an AppleScript written by someone else:
Search time: Sunday April 28, 2019 at 07:21:07
Search complete. Nothing found.
But, when I use cat I get ...
0
votes
1
answer
87
views
Automatic head in ms-word
I’m creating a template in word and would like to include a text field in the cover for the title, something like "Document Title", that will be replaced by the user with the real title the want to ...
19
votes
2
answers
27k
views
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
...
8
votes
3
answers
15k
views
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
<!-- This is the hidden line i want to ...
3
votes
1
answer
353
views
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 ...
1
vote
1
answer
2k
views
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 ...
1
vote
1
answer
275
views
Head waits for full stdin before printing
When one runs
ls | head
head seems to wait for the full output of the piped command before printing to screen. This is undesirable when the command will take a very long time to run, such as when ...
0
votes
0
answers
563
views
Copy huge file skipping first line using dd in Linux
I was trying to copy the content of a huge file (10GB) to another skipping the first line (as in head -n1). I tried multiple ways of head, tail, awk and sed. Settled on using tail -n+2 > ./xab.1
...
14
votes
7
answers
30k
views
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....
1
vote
1
answer
35
views
Using head to see up to a character
I have some C source files and a lot of them have a single, 1-line comment at the top that offers a short description of what that program does (I haven't done anything complex enough to warrant a ...
1
vote
1
answer
1k
views
Extracting part of a large SQL dump
Is there a way to chain commands like grep and head together to extract a portion of a file?
The problem is that somewhere in my .sql file I have an old data that I need to compare to new data and I ...
1
vote
1
answer
2k
views
head and cat don't recognize Microsoft Excel text files
I have a large .xls file with 53760 rows and 19 columns. I saved it as Tab Delimited Text in order to pre-process it through command line tools and load it into R later. However, when I run
head ...
2
votes
1
answer
2k
views
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 ...
1
vote
1
answer
1k
views
head hangs or doesn't terminate on Linux
I'm using, (uname -a says) Linux ip-x-x-x-x 2.6.21.7-2.fc8xen-ec2-v1.0 #1 SMP Tue Sep 1 10:25:30 EDT 2009 x86_64 GNU/Linux.
I've got a script, foo.sh with 100 lines of code and when I run
head -...
5
votes
1
answer
6k
views
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 ...
2
votes
3
answers
5k
views
zcat | head : write error from large gz file
I was trying zcat to get only the first 1M lines of a compressed .gzip file into a new one.
However, I get the following error:
$ zcat path/to/R2.fq.gz | head -100 >R2.fqtest
head: write error: ...
81
votes
6
answers
83k
views
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 ...
2
votes
1
answer
405
views
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 -...
0
votes
1
answer
176
views
Read a Section of Lines from a File in Linux
I'm trying to export lines 100 to 1,000,100 from a file with 62 million lines. So far I've found this command:
head -1100000 input > output
But head does not take an offset option.
Thoughts?
3
votes
2
answers
3k
views
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 ...
24
votes
4
answers
19k
views
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 ...
2
votes
1
answer
5k
views
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 ...
3
votes
2
answers
237
views
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 ...
5
votes
2
answers
7k
views
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, ...
3
votes
3
answers
2k
views
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 ...