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,

marked as duplicate by jw013, George M, manatwork, Renan, jasonwryan Jan 18 '13 at 20:15

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    If you have xsel installed you could use sed with xsel. sed -n '2000,2150p' youfile| xsel – McNisse Jan 18 '13 at 10:01
  • @McNisse Why do you need xsel? – Bernhard Jan 18 '13 at 10:07
  • To copy the lines directly into the clipboard. – McNisse Jan 18 '13 at 10:32
  • 2
    If bandwidth is not an issue, you can use editor or pager like more or less remotely. Remember to resize the PuTTY window to get some more context. – peterph Jan 18 '13 at 10:59
  • @McNisse "I just want to copy these lines to another file" – Bernhard Jan 18 '13 at 11:35
10

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
  • 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 - linuxquestions.org/questions/linux-software-2/… The following outputs lines 10 to 30... – Rich Jan 18 '13 at 11:47
  • 3
    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
  • 4
    I don't think this really answers the question. Also, why are you using cat here? – Bernhard Jan 18 '13 at 11:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.