user2135240
user2135240

Reputation: 171

Selecting a part of a file and copying that into new file in Linux

How can I copy a particular content of a file into a new file using Linux?

For example I have file called test.log file and it contains some 1000 lines. From those 1000 lines I need to copy the lines between 200 - 700 lines.

Is there any single line command in LINUX/UNIX?

Upvotes: 15

Views: 27149

Answers (2)

Kent
Kent

Reputation: 195079

try this line:

awk 'NR>700{exit}NR>=200{print $0 > "newfile"}' yourlog

the line above will stop processing after line 700. it is helpful if your log file is huge.

Upvotes: 4

Anubhab
Anubhab

Reputation: 1786

Try this:

sed -n '200,700p' logfilename > destinationFilename

Upvotes: 24

Related Questions