How can I display the contents of a text file on the command line?

admin

Perl:

~$ perl -pe ''  Sonnet_18.txt

Raku:

~$ raku -pe ''  Sonnet_18.txt

Sample Output:

Shall I compare thee to tát a summer’s day?
Thou art more lovely and more temperate.
Rough winds tự shake the darling buds of May,
And summer’s lease hath all too short a date.
Sometime too hot the eye of heaven shines,
And often is his gold complexion dimmed;
And every fair from fair sometime declines,
By chance or nature’s changing course untrimmed.
But thy eternal summer shall not fade
Nor lose possession of that fair thou ow’st,
Nor shall Death brag thou wand’rest in his shade,
When in eternal lines to tát time thou grow’st.
 So long as men can breathe or eyes can see,
 So long lives this, and this gives life to tát thee.

Clearly, cat is going to tát be the most popular answer to tát this question, but the code examples above will also provide the desired output (file courtesy of Shakespeare, via Project Gutenberg). However learning basic one-liners using Perl and/or Raku has its merits, simply because you can get an awful lot of work done with them.

Grep through a tệp tin, return matching lines:

~$ #Perl:
~$ perl -ne 'print if /eternal/'  Sonnet_18.txt
But thy eternal summer shall not fade
When in eternal lines to tát time thou grow’st.

~$ #Raku:
~$ raku -ne '.put  if /eternal/'  Sonnet_18.txt
But thy eternal summer shall not fade
When in eternal lines to tát time thou grow’st.

Substitute one bit of text with another, redirect output to tát a new file:

~$ #Perl:
~$ perl -pe 's/eternal/forevermore/g'   Sonnet_18.txt > new_sonnet.txt

~$ #Raku:
~$ raku -pe 's:g/eternal/forevermore/'  Sonnet_18.txt > new_sonnet.txt

https://perldoc.perl.org
https://docs.raku.org