0

So in Linux, less is used to read files page by page for better readability. I was wondering if you can do something like

less file.txt > output.txt

to get one page worth of file.txt and output/write it to output.txt.

(Asking on behalf of yyin stackoverflow OP)

1

there's a sequence of less commands that can do what you want with less:

1) type | , the prompt will change to |mark:

2) type . ( a dot) , the prompt will change to !

3) type tee output.txt to write the current page to that file.

What a page is on console? From the xterm man page:

page
Select all visible lines, i.e., the page.

If the console is resized, the number of lines will change :-p

0

A dirty way of doing somewhat like this (over the top-of-my-head) could be:

$ script someFile // to make a typescript of the terminal session
$ less file.txt
<Quit less(1) now>
$ exit // this exits the script(1)

Check out the content of "someFile" file now as it should give some idea as to what you need, although cleaning will be required unless you can improve (dig a bit deeper).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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