6

Possible Duplicate:
cat line X to line Y on a huge file

Very simple issue but can't seem to find a simple resolution!

I have a massive text file from which I only need around 150 lines. The lines are really long and therefore viewing it in putty is a bit of a nightmare. I just want to copy these lines to another file so that I can view it properly in an editor. (I can't view the original file in an editor as my Windows machine can't handle it).

The lines I want start at around line 2000.

Thanks,

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Rich
  • 167
  • 2
  • 2
  • 5

2 Answers2

11

I have an easy shell function for it (put in .bashrc), which uses sed

printLine () 
{ 
    sed -n -e "$1p" "$2"
}

You can easily use it by

$ printLine 2000,2250 file

I am using the function, because I always forget the correct sed-syntax.

You want to store the output in a different file, than it is easy:

$ printLine 2000,2250 file > output
Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
Bernhard
  • 11,992
  • 4
  • 59
  • 69
  • I'm using ksh (should have mentioned that) and printLine doesn't work :S – Rich Jan 18 '13 at 11:42
  • Sorted it... thanks to kev82 here - http://www.linuxquestions.org/questions/linux-software-2/cat-output-specific-number-of-lines-130360/ The following outputs lines 10 to 30... – Rich Jan 18 '13 at 11:47
  • 4
    `head -30 text.file | tail -20 > output.file` – Rich Jan 18 '13 at 11:50
  • @Rich ksh also supports functions, afaik, so you can probably easily port it. – Bernhard Jan 18 '13 at 12:19
1

If you just look for a certain token, the grep command could be useful.

cat filename | grep pattern > extractedFilename
Christian Graf
  • 189
  • 1
  • 6