1

I am using ed a unix line editor and the book i'm reading says to type 1,$p (also works in vim)

after trial and error I figured the first value means the line number but whats the purpose to $p? from what i can tell is the 1 goes to the beginning of the line and $p goes to the EOF and displays to me everything it picked up. is this true or am i way off?

Exploit
  • 6,278
  • 19
  • 70
  • 103

1 Answers1

4

The 1,$ part is a range. The comma separates the beginning and end of the range. In this case, 1 (line 1) is the beginning, and $ (EOF) is the end. The p means print, which is the command the range is being given to, and yes.. it displays to you what is in that range.

In vim you can look at :help :range and :help :print to find out more about how this works. These types of ranges are also used by sed and other editors.

They probably used the 1,$ terminology in the tutorial to be explicit, but note that you can also use % as its equivalent. Thus, %p will also print all the lines in the file.

Conner
  • 30,144
  • 8
  • 52
  • 73
  • thank you for that very clear explanation!, i'm not there yet in the book but what other commands can i put instead of print? And is there a way to clear the output like the terminal command clear? – Exploit Sep 27 '12 at 05:10
  • @SarmenB. Here's a list of [commands](http://www.gnu.org/software/ed/manual/ed_manual.html#Commands). The ones with `(.,.)` in front of them take a range, but default to using the current line. The ones with `(1,$)` in front of them also take a range, but default to using the entire file. – Conner Sep 27 '12 at 05:34