I want to practice using head
, uniq
and cut
, for this data here.
I know this thread but it focuses too much on cat
and external programs.
I would like a simpler answer.
I want to take interval from the data file, e.g. lines 800-1600.
I am not sure if cut
is intended for this task with the flags -n
and -m
. At least, I could not extract lines, just patterns in some byte locations.
Running mikeserv's answer
Code 1.sh:
for i in 2 5
do head -n"$i" >&"$((i&2|1))"
done <test.tex 3>/dev/null
and data
1
2
3
4
5
6
7
8
9
10
11
Running the code as sh 1.sh
gives empty line as an output, although it should give 3 4 5 6 8
. What do I understand wrong in Mike's answer?
How would you select line intervals in data by sed
, tail
, head
and cut
?
sed '800,1600 ! d' file
– Costas Jun 26 '15 at 18:11tail -n +800 file | head -n 800
(forhead
1600 - 800) – Costas Jun 26 '15 at 18:12tail -n 800
andtail -n +800
– Costas Jun 26 '15 at 18:21tail -n +800
gives everything after the match, whiletail -n 800
gives 800 lines from the end. Nice overloading of the flag! – Léo Léopold Hertz 준영 Jun 26 '15 at 18:25cut
anduniq
you'll see why there's no answer there involvingcut
/uniq
. – don_crissti Jun 26 '15 at 18:32xargs
and you can do nice things with these commands. – Léo Léopold Hertz 준영 Jun 26 '15 at 21:05