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
3
votes
1 answer

Only display the largest number in head

I use sort -r | head and get the out put like this: 8 a1 8 a2 5 a3 5 a4 4 a5 4 a6 4 a7 4 a8 4 a9 4 a0 What can I do to make the output like this: 8 a1 8 a2 only the largest k1 number show up????
Sal Kuk
  • 53
  • 4
3
votes
2 answers

Cut command including a space which is confusing head command?

I am trying to use the output of a cut command into a head command to output a specific line. I find that if the number being fed into the head command 10+ it works fine. So I am wondering if the cut -c1-2 is including white space for the single…
Tanya
  • 33
  • 3
3
votes
1 answer

Piping Perl script output to head -n 10 kills script after printing 10 lines

My Perl script outputs and logs many lines of text, and it does some cleanup and compresses some logs in an END block. The problem is when you do something like this on the command line: perl myscript.pl | head -n 10 This causes the script to die…
hmatt1
  • 4,939
  • 3
  • 30
  • 51
3
votes
2 answers

head output till a specific line

I have a bunch of files in the following format. A.txt: some text1 more text2 XXX more text .... XXX . . XXX still more text text again Each file has at least 3 lines that start with XXX. Now, for each file A.txt I want to…
Graddy
  • 2,828
  • 5
  • 19
  • 25
2
votes
2 answers

What does "-" before an argument to "head" do?

I have a simple code here but am having some trouble understanding it. $ more $1 | head -$2 | tail -1 For the second parameter, I am running a test txt $ more joe.txt i am trying something else to see if head works the way it should work When I…
2
votes
5 answers

Applying Unix's Head on AWK Through Find Command

I want to output top 10 lines of AWK command in the list of files given by find, using this snippet: $ find . -name "*.txt" -print -exec awk '$9 != ""' \| head -n10 {} \; Note also that I want to print out the file names being processed. But why I…
neversaint
  • 60,904
  • 137
  • 310
  • 477
2
votes
2 answers

How can I delete files over (n) days old but leave (n) files regardless of age?

I wrote the following in PHP but I was wondering if there is an elegant way to do this in a Linux shell script? Basically delete files over (n) days old, but leave the (n) newest files regardless of age. PHP foreach (glob("backup/*.db") as…
2
votes
2 answers

Grep inside files returned from ls and head

I have a directory with a large number of files. I am attempting to search for text located in at least one of the files. The text is likely located in one of the more recent files. What is the command to do this? I thought it would look something…
KPrince36
  • 2,886
  • 2
  • 21
  • 29
2
votes
2 answers

Unix shell - copy first 300 lines to new file

I've been trying to solve this for days and nothings seems to work. Copy first 300 lines of a file1 to a new file called file2. This file contains phone number information, already sorted by last name, which is the first field in each record. head…
1
vote
1 answer

How to read and print first head of a file in R?

I want to print a head of a file in R. I know how to use read.table and other input methods supported by R. I just want to know R alternatives to unix command cat or head that reads in a file and print some of them. Thank you, SangChul
Sangcheol Choi
  • 841
  • 1
  • 12
  • 19
1
vote
2 answers

Heads and Tails - Trying to get first line and last ten lines of each file

I've got a directory of output files that I'd like to display the first line of each file and the last ten lines of each file in order. I've got part of the command down: ls output/*Response | sort -t_ --key=2 -g | xargs tail | less Which give me…
phileas fogg
  • 1,905
  • 7
  • 28
  • 43
1
vote
1 answer

how to filter special characters and blank lines in unix

I want to display lines containing blank lines and special characters (?#!%#). i used grep command for special characters but its not working for blank line. grep -n '[]?#!*%[]' file if someone can please try this one? Thank you
1
vote
1 answer

List of unique headers recursively on files matching pattern

I want the unique headers for a bunch of csv files whose names contain ABC or XYZ. Within a single directory, I can sort of get what I need with: head -n ` *.csv > first.txt cat -A first.txt | tr ',' '\n' | sort | uniq Of course, this isn't…
Lorem Ipsum
  • 4,020
  • 4
  • 41
  • 67
1
vote
2 answers

Concatenating CSV files in bash preserving the header only once

Imagine I have a directory containing many subdirectories each containing some number of CSV files with the same structure (same number of columns and all containing the same header). I am aware that I can run from the parent folder something…
David
  • 7,652
  • 21
  • 60
  • 98
1
vote
1 answer

Unix HEAD command implementation in C fails on larger lines

I am currently implementing the Unix HEAD command with C and using only system functions. So far, it works perfectly on files, which have lines with less length than the one that I specified for my buffer: #include #include…
wencakisa
  • 5,850
  • 2
  • 15
  • 36