The tag has no wiki summary.

learn more… | top users | synonyms

4
votes
3answers
159 views

Copy a specific percentage of each file in a directory to a new file

For example, we have N files (file1, file2, file3 ...) We need first 20% of them, the result directory should be like (file1_20, file2_20, file3_20 ...). I was thinking use wc to get the lines of ...
2
votes
2answers
146 views

Negative arguments to head / tail

Variants of this question have certainly been asked several times in different places, but I am trying to remove the last M lines from a file without luck. The second most voted answer in this ...
0
votes
0answers
56 views

Why does GNU head/tail read the whole file? [duplicate]

I have a huge file and want to see its beginning and end. However, when I use head and tail, it apparently tries to read the whole file. Since the file is larger than a terabyte, this takes a very ...
1
vote
1answer
82 views

Split very big xml file into little pieces with specific line number count

This is how I did to extract the first 100000 lines from my big xml file (2gb): head source.xml -n 100000 > part.xml How can I keep splitting them to 100000 line (or specific file size chunks) ...
4
votes
3answers
87 views

Time required to do pipe output to head/tail [duplicate]

There are lots of txt files in a directory. If I do time wc -l *.txt | head it takes real 0m0.032s user 0m0.020s sys 0m0.008s If I do time wc -l *.txt | tail it takes real 0m0.156s ...
5
votes
4answers
281 views

Is there a difference between read, head -1, and sed 1q?

The following commands seem to be roughly equivalent: read varname varname=$(head -1) varname=$(sed 1q) One difference is that read is a shell builtin while head and sed aren't. Besides that, is ...
2
votes
4answers
322 views

Only cat from specific line X (with a pattern) to other specific line Y (with a pattern)

A little extended problem from "cat line x to line y on a huge file": I have a huge file (2-3 GB). I'd like to cat/print only from the line having "foo:" to the line having "goo:". Assume that "foo:" ...
1
vote
3answers
87 views

Pulling lines n to m from list of files found

Ultimately I need to grab lines 3-53 from ever csv in each subdirectory. I grabbed the lines like so (cat isn't necessarily required): cat /[path]/[file].csv | head -53 | tail -51 And the files ...
2
votes
1answer
58 views

Command to print few consecutive lines from middle of a file [duplicate]

For a file containing 20 lines, lines 6-10 can be printed using following command: head -10 filename | tail -5 Can this exactly same thing be done without using 'head' and 'tail' commands ?? ...
1
vote
1answer
53 views

How to echo from specific line of a file to another specific line [duplicate]

Assume I have a file with about 10000 lines. How can I print 100 lines, starting from line 1200 to line 1300?
0
votes
1answer
100 views

How to make xargs ping and head output as expected?

Given an array of domains I would like to obtain their IP addresses, in the following format: 98.139.183.24 98.137.236.24 This script #!/bin/bash domains=(yahoo.com yahoo.ca) printf "%s\0" ...
2
votes
2answers
242 views

Use output from head to copy files with spaces

I have 11 files with spaces in its name in a folder and I want to copy the newest 10. I used ls -t | head -n 10 to get only the newest 10 files. When I want to use the expression in a cp statement I ...
4
votes
4answers
1k views

How to get lines 10 to 100 from a 200 line file into a new file [duplicate]

I have file with 200 lines. I need to extract lines from 10 to 100 and put them into a new file. How do you do this in unix/Linux? What are the possible commands you could use?
0
votes
1answer
88 views

removing the last line of a file not working? [duplicate]

I have this TXT file that is created by a bash script and at the end I want to remove the last line of that file that is an empty one. head --lines=-1 r3.txt > r4.txt sed '$d' r3.txt > r4.txt ...
0
votes
3answers
88 views

Is it possible to change the default COUNT value of tail and head?

The less command accepts its defaults with an environment variable LESS, so you can export LESS='-F -g -i -M -R -S -w -X -z-4' at the beginning of your session. Is it possible to change the ...
1
vote
2answers
462 views

will tail with piping read whole file?

I want to read a big log file with 10000 lines everytime. and I use this command: tail -c +offset somefile | head -n 10000 my question is, with the piping of head, will tail read the whole file? ...
4
votes
1answer
170 views

How can I colorize head, tail and less, same as I've done with cat?

I've got 'color cat' working nicely, thanks to others (see How can i colorize cat output including unknown filetypes in b&w?). In my .bashrc: cdc() { for fn in "$@"; do source-highlight ...
2
votes
1answer
1k views

Search and Filter Text on large log files

I use the tail, head and grep commands to search log files. Most of the time the combination of these 3 commands, in addition to using pipe, gets the job done. However, I have this one log that many ...
2
votes
1answer
175 views

POSIX head and tail not feature equivalent

The documentation for POSIX tail's -n option says that The origin for counting shall be 1; that is, -n +1 represents the first line of the file, -n -1 the last. So tail -n 10 (used later on the ...
11
votes
1answer
412 views

How to do `head` and `tail` on null-delimited input in bash?

find command can output names of files as a null-delimited strings (if -print0 is provided), and xargs can consume them with -0 option turned on. But in between, it's hard to manipulate that ...
1
vote
1answer
152 views

head command options and reading man files

I have two environments: Mac and Linux. I wonder about the head command: it can show just 2 lines of text if I invoke it like so: vim --version | head -2 I saw this online and ran to the man page ...
4
votes
0answers
78 views

Combing head and tail in a single call via pipe [duplicate]

On a regular basis, I am piping the output of some program to either head or tail. Now, suppose that I want to see the first AND last 10 lines of piped output, such that I could do something like ...
2
votes
1answer
126 views

Why can't I trim a file using `head`? [duplicate]

Given a file, foo.txt: 1 2 3 4 5 Say we want to change it to contain: 1 2 3 Why does head -n3 foo.txt > foo.txt leave foo.txt empty?
6
votes
2answers
2k views

Why does Subversion give a broken pipe error when piped into head?

If I do a svn log | head after the tenth line of output I get an error message: svn: Write error: Broken pipe What's going on here? I haven't seen any other command do this when used with head. ...
0
votes
1answer
123 views

Redirecting head output for update hosts file [duplicate]

Possible Duplicate: How can I make iconv replace the input file with the converted output? I'm writing a script to change the content of my hosts file but I got stuck on the head output ...
17
votes
8answers
19k views

Command to display first few and last few lines of a file

I have a file with many rows, and each row has a timestamp at the starting, like [Thread-3] (21/09/12 06:17:38:672) logged message from code..... So, I frequently check 2 things from this log file. ...
30
votes
5answers
45k views

cat line X to line Y on a huge file

Say I have a huge text file (>2GB) and I just want to cat the lines X to Y (e.g. 57890000 to 57890010). From what I understand I can do this by piping head into tail or viceversa, i.e. head -A ...
6
votes
1answer
639 views

Peculiar piping grep/head behavior

I'm helping the netadmin here with a perl regex to automate operating on some snapshots from our SAN and our scripts does stuff like this: varinit1=$(iscsiadm -m session | grep rbmsdata1 | head -n1 | ...
5
votes
2answers
1k views

Why does `cat`ing a file into itself erase it? [duplicate]

Possible Duplicate: IO redirection and the head command I just wanted to remove all but the first line of a file. I did this: head -1 foo.txt ... and verified that I saw only the first ...
2
votes
2answers
3k views

How to execute this particular shell command from Python?

OK, so, I have this non-functional shell script, which I am rewriting piece by piece in python, except I am getting an "unexpected "|" error" from the shell (see below): #/bin/sh LINES=`cat $@ | wc ...
24
votes
5answers
9k views

How to obtain inverse behavior for `tail` and `head`?

Is there a way to head/tail a document and get the reverse output; because you don't know how many lines there are in a document? I.e. I just want to get everything but the first 2 lines of foo.txt ...