Skip to content
Advertisement

vi command to copy certain lines to another file

I have a log file with thousands of lines. I want to copy certain logs ranging between two line numbers to another file so that I can share them within team.

For example – I want to copy text from line number 1000 to line 1200 to another file say issueLog.log

What is the shortest way to do this?

Note: We are not using vim.

Advertisement

Answer

Open the original file in Vi and type the following command.

:1000,1200w issueLog.log

(or)

Use GNU sed

sed -n 1000,1200p original-file > issueLog.log

(or)

Use perl

perl -ne 'print if 1000..1200' original-file > issueLog.log

(or)

Use awk

awk 'NR>=1000&&NR<=1200' original-file > issueLog.log
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement