1

Assume I have a file with about 10000 lines.

How can I print 100 lines, starting from line 1200 to line 1300?

polym
  • 10,852

1 Answers1

4

With awk this would be awk 'NR >= 1200 && NR <= 1300'

with sed: sed -n '1200,1300 p' FILE

with head and tail: head -n 1300 FILE | tail -n 100

so many options, so many answers on stackexchange :)

b13n1u
  • 524
  • I suggest that this page be fixed. The page question is "How to echo from specific line of a file to another specific line" yet the answer is a non-sequitur regarding how to print a range of lines. – unifex Jun 17 '23 at 19:32
  • Answer to question as asked: Insert line 3 from a file named things.txt to line 6 of a file named numbers.txt using head tail and ex:

    LINE=$(head -3 things.txt |tail -1) ex numbers.txt <<eof 6 insert "$LINE" . xit eof

    #--------

    Append rather than insert to say, line 6 do the following with sed:

    LINE=$(head -3 things.txt |tail -1) sed '6s/$/ "$LINE"/' numbers.txt


    This use of sed will only echo the change without writing it, if you want to save the changes you can echo the output to a new file

    sed '6s/$/ "$LINE"/' numbers.txt >numbers2.txt

    – unifex Jun 17 '23 at 19:33