Is there something like a 'lorem ipsum generator'? I know it exists in Latex, and even in LibreOffice, but I'm looking for a terminal command. I would like to type something like loremipsum 10 >> file1.txt that would give me the first 10 paragraphs of lorem ipsum, each paragraph ended with one LF-character and 1 empty white line between each paragaph. And the output would be redirected to a file called file1.txt in the current directory.
- 522,931
- 91
- 1,010
- 1,501
- 383
- 1
- 3
- 6
-
2[libtext-lorem-perl](http://search.cpan.org/dist/Text-Lorem/bin/lorem) – Alex Oct 22 '13 at 21:49
-
2Try this: http://code.google.com/p/pypsum/wiki/pypsum – Kyle Strand Oct 22 '13 at 21:55
-
1http://www.lipsum.com has always been there when I needed it (yes, I know it isn't local, just offering another way). – msw Oct 23 '13 at 02:58
9 Answers
You can use the perl library libtext-lorem-perl. Here a short example, feel free to expand it to parse command line arguments, etc.
#!/usr/bin/env perl
use Text::Lorem;
my $text = Text::Lorem->new();
$paragraphs = $text->paragraphs(10);
print $paragraphs;
- 33,188
- 10
- 112
- 146
-
1i got this error: Can't locate Text/Lorem.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .) at ./loremipsum.pl line 3. BEGIN failed--compilation aborted at ./loremipsum.pl line 3. – Frank Oct 22 '13 at 22:12
-
1
-
7On Debian the `libtext-lorem-perl` package contains simple `lorem` command, so there is no urgent need for custom scripts. – Josef Kufner Dec 29 '14 at 16:44
found this at Bash One-Liners
tr -dc a-z1-4 </dev/urandom | tr 1-2 ' \n' | awk 'length==0 || length>50' | tr 3-4 ' ' | sed 's/^ *//' | cat -s | sed 's/ / /g' |fmt
must be limited by another command or generates text infintely
- 217
- 2
- 2
-
2
-
4
-
1@ssc Try installing GNU `tr` (`brew install coreutils`) and replace `tr` with `gtr`. – jdlm May 16 '17 at 12:45
-
tr on a Mac doesn't behave the same as on Linux. See this post: https://unix.stackexchange.com/questions/141420/tr-complains-of-illegal-byte-sequence – aakoch Oct 03 '18 at 18:35
-
If you want to awk on Mac you will need to install gawk `brew install gawk` just because of the type of linux that run's on mac. – PrestonDocks Jul 24 '19 at 20:54
Fedora and Arch Linux's AUR have a lorem-ipsum-generator package:
lorem-ipsum-generator -p 10 -l
will do exactly what you are asking for.
Another DIY alternative :
info bash -o -|shuf -n50|sed 's/ */ /g;s/^ //'|fmt -w 90
This outputs bash documentation into stdout, pipes it to shuf which randomly selects 50 lines, then sed removes multiple and leading spaces, and finally fmt formats it to lines approximately 90 characters long.
Of course this is just a starting point and you might need to refine the output, for which sed, tr and other string manipulators will help.
shuf, fmt and tr are parts of coreutils (which has a great chance of being already installed on your GNU/Linux distribution).
- 19,561
- 18
- 86
- 152
- 3,153
- 29
- 37
-
I fixed up your sed program a little bit and added a head to the pipe so you can select the number of lines you want: `info -a bash -o - | shuf -n50 | sed -n 's/ */ /g;s/^ //;/./p' | fmt -w 90 | head -8` – OscarJ Apr 13 '19 at 15:21
While not technically Lorem Ipsum or a local binary, there is an API on Metaphorpsum which can output similar text but in English. I call it with curl like so:
curl http://metaphorpsum.com/sentences/3curl http://metaphorpsum.com/paragraphs/20
Better still, you can define the API call as a function in your bash profile or scripts like this:
loremipsum () {
if [ "${1}" = "" ] || [ "${2}" = "" ]; then
echo "Usage: loremipsum [paragraphs, sentences] [integer]"
else
curl -s http://metaphorpsum.com/"${1}"/"${2}" && printf "\n"
fi
}
You can then use it in a very similar way to your example:
loremipsum paragraphs 10 >> file1.txt
- 71
- 1
- 3
Generate random lorem ipsum text using Metaphorpsum API
Default to 3 sentences
lorem() {
curl -s http://metaphorpsum.com/sentences/${1-3} | pbcopy
pbpaste | grep .
}
BOUNS: avoids curl progress, removes % from output, and adds to your clipboard for ease of pasting, while still displaying to stdout
Example usage #1:
lorem
It's an undeniable fact, really; the starter is an outrigger. One cannot separate professors from moody gases. Few can name an unpraised oil that isn't a leery relative.
Example usage #2:
lorem 1
The shrinelike swedish comes from a foremost syrup.
- 523
- 5
- 7
The following command has been useful for me in many situations:
base64 /dev/urandom | awk '{print(0==NR%10)?"":$1}' | sed 's/[^[:alpha:]]/ /g' | head -50
This gives 50 lines where non-alphabetical characters obtained randomly from base64 /dev/urandom have been replaced by blank spaces: sed 's/[^[:alpha:]]/ /g'. Each line whose index is a multiple of 10 is replaced by the empty string (in order to simulate separation of paragraphs): awk '{print(0==NR%10)?"":$1}'.
You can add | awk '{ print NR,$0 }' at the end to get numbered lines (or any other that meets your needs). An executable bash-script lipsum that accepts the number of lines as argument could be useful.
#!/usr/bin/bash
base64 /dev/urandom | awk '{print(0==NR%10)?"":$1}' | sed 's/[^[:alpha:]]/ /g' | head -$1 | awk '{ print NR,$0 }'
lipsum 100 > output_file
- 321
- 3
- 5
-
(1) Your awk command discards every tenth line. It doesn’t matter for random text, but for less trivial applications you might want to use `awk '{print}0==NR%10{print""}'` to add a blank line after every tenth line. (2) Yes, `awk '{ print NR,$0 }'` will print line numbers, but note that there are other tools that are specifically designed to do that (like `nl` and `cat -n`). – G-Man Says 'Reinstate Monica' Apr 23 '19 at 03:53
-
Thanks @G-Man. (1) For less trivial applications you might consider `base64 /dev/urandom | sed '{0~10 s/^.*//;0~10!s/[^A-z]/ /g;50q0}'` but this one seems less clear to me. (2) Note that in this case, `nl` and `cat -n` do not give the same line-numbering. – lezambranof Apr 23 '19 at 06:40
-
Range `[^A-z]` can be problematic in some architectures, in such case use `base64 /dev/urandom | sed '{0~10 s/^.*//;0~10!s/[^A-Za-z]/ /g;50q0}'` – lezambranof Feb 13 '21 at 21:46
I made a simple offline solution by means of one of the many lorem ipsum generators on the web. Store a moderate amount of text -- say 20 paragraphs -- in a file, and make the following script executable:
#!/bin/bash
file=$HOME/lib/text/lorem_ipsum && cat $file
- 117
- 1
Lorem Ipsum Generator Web site : - http://lorem-ipsum.perbang.dk/ (you can select nb of paragraph, etc)
- 1