Pergunta

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?

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top