28

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.

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
Frank
  • 383
  • 1
  • 3
  • 6

9 Answers9

17

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;
Marco
  • 33,188
  • 10
  • 112
  • 146
  • 1
    i 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
    Sorry, I didn't install the libtext-lorem-perl package. Will try again. – Frank Oct 22 '13 at 22:16
  • 7
    On 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
10

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

chillin
  • 217
  • 2
  • 2
7

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).

Sparhawk
  • 19,561
  • 18
  • 86
  • 152
  • 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
7

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/3
  • curl 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

Dials Mavis
  • 71
  • 1
  • 3
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.

jasonleonhard
  • 523
  • 5
  • 7
1

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

lezambranof
  • 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
0

Found two other python libs to be used

dimitrieh
  • 109
  • 4
0

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
untill
  • 117
  • 1
0

Lorem Ipsum Generator Web site : - http://lorem-ipsum.perbang.dk/ (you can select nb of paragraph, etc)

Martin
  • 1