Skip to main content
Tweaked formatting and capitalization.
Source Link

How can I split the output of a command on a delimiter, in this case a new line, and then select one line at random?

An example of what I'm trying to do is:

curl -s http://www.compciv.org/files/pages/nyt-sample/ | pup 'article p text{}' \
        | sed 's/^[ \r\n\t]*//'

Whichwhich outputs:


The fine of $35 million in each of two civil penalties, for a total of $70 million, is a record for the National Highway Traffic Safety Administration.


After becoming a grandmaster at the tender age of 13, Sam Sevian is getting some help from the chess champion Garry Kasparov.


In a small stand against gentrification, the nonprofit Wildflowers Institute has helped San Francisco’s gritty Tenderloin neighborhood define its cultural assets.


The currency has fallen because investors fear that the eurozone is stuck in a quagmire and its leaders are not doing much to pull it out.


President Obama is facing opposition from his party to one of his top priorities: winning the power to negotiate international trade pacts and speed them through Congress.


The fine of $35 million in each of two civil penalties, for a total of $70 million, is a record for the National Highway Traffic Safety Administration.


After becoming a grandmaster at the tender age of 13, Sam Sevian is getting some help from the chess champion Garry Kasparov.


In a small stand against gentrification, the nonprofit Wildflowers Institute has helped San Francisco’s gritty Tenderloin neighborhood define its cultural assets.


The currency has fallen because investors fear that the eurozone is stuck in a quagmire and its leaders are not doing much to pull it out.


President Obama is facing opposition from his party to one of his top priorities: winning the power to negotiate international trade pacts and speed them through Congress.

How can I split on the newlines and then select just one so I'd get something just like

The currency has fallen because investors fear that the eurozone is stuck in a quagmire and its leaders are not doing much to pull it out.
The currency has fallen because investors fear that the eurozone is stuck in a quagmire and its leaders are not doing much to pull it out.

How can I split the output of a command on a delimiter, in this case a new line, and then select one line at random?

An example of what I'm trying to do is:

curl -s http://www.compciv.org/files/pages/nyt-sample/ | pup 'article p text{}' | sed 's/^[ \r\n\t]*//'

Which outputs:


The fine of $35 million in each of two civil penalties, for a total of $70 million, is a record for the National Highway Traffic Safety Administration.


After becoming a grandmaster at the tender age of 13, Sam Sevian is getting some help from the chess champion Garry Kasparov.


In a small stand against gentrification, the nonprofit Wildflowers Institute has helped San Francisco’s gritty Tenderloin neighborhood define its cultural assets.


The currency has fallen because investors fear that the eurozone is stuck in a quagmire and its leaders are not doing much to pull it out.


President Obama is facing opposition from his party to one of his top priorities: winning the power to negotiate international trade pacts and speed them through Congress.

How can I split on the newlines and then select just one so I'd get something just like

The currency has fallen because investors fear that the eurozone is stuck in a quagmire and its leaders are not doing much to pull it out.

How can I split the output of a command on a delimiter, in this case a new line, and then select one line at random?

An example of what I'm trying to do is:

curl -s http://www.compciv.org/files/pages/nyt-sample/ | pup 'article p text{}' \
        | sed 's/^[ \r\n\t]*//'

which outputs:


The fine of $35 million in each of two civil penalties, for a total of $70 million, is a record for the National Highway Traffic Safety Administration.


After becoming a grandmaster at the tender age of 13, Sam Sevian is getting some help from the chess champion Garry Kasparov.


In a small stand against gentrification, the nonprofit Wildflowers Institute has helped San Francisco’s gritty Tenderloin neighborhood define its cultural assets.


The currency has fallen because investors fear that the eurozone is stuck in a quagmire and its leaders are not doing much to pull it out.


President Obama is facing opposition from his party to one of his top priorities: winning the power to negotiate international trade pacts and speed them through Congress.

How can I split on the newlines and then select just one so I'd get something just like

The currency has fallen because investors fear that the eurozone is stuck in a quagmire and its leaders are not doing much to pull it out.
Source Link

Split stdout on delimiter and select line at random?

How can I split the output of a command on a delimiter, in this case a new line, and then select one line at random?

An example of what I'm trying to do is:

curl -s http://www.compciv.org/files/pages/nyt-sample/ | pup 'article p text{}' | sed 's/^[ \r\n\t]*//'

Which outputs:


The fine of $35 million in each of two civil penalties, for a total of $70 million, is a record for the National Highway Traffic Safety Administration.


After becoming a grandmaster at the tender age of 13, Sam Sevian is getting some help from the chess champion Garry Kasparov.


In a small stand against gentrification, the nonprofit Wildflowers Institute has helped San Francisco’s gritty Tenderloin neighborhood define its cultural assets.


The currency has fallen because investors fear that the eurozone is stuck in a quagmire and its leaders are not doing much to pull it out.


President Obama is facing opposition from his party to one of his top priorities: winning the power to negotiate international trade pacts and speed them through Congress.

How can I split on the newlines and then select just one so I'd get something just like

The currency has fallen because investors fear that the eurozone is stuck in a quagmire and its leaders are not doing much to pull it out.