Reputation: 11
And the initial file is empty. Is there any command? I tried sed but it does not work on an empty file. Any ideas?
Upvotes: 0
Views: 129
Reputation: 360345
I'm assuming that this is for a bar bet or something like that.
Here are some options:
shuf
is a part of Linux coreutils. It can accept a string and an output file as arguments.
shuf -e -o outputfile 'this is some text'
You could also use that to output only a newline then use sed -i
.
This does something similar. The dd
creates a file with one zero byte, then sed
writes a string to it.
dd if=/dev/zero of=outputfile bs=1 count=1
sed -i 's/.*/foo\n/' outputfile
Of course there's Perl:
perl -e 'open $fh, ">", "outputfile"; print $fh "foo\n"'
Upvotes: 1
Reputation: 1055
You could use the line editor:
ed tmp.tmp << EOC
a
PUT STRING HERE
.
w
q
EOC
Upvotes: 2