Create a file with generated content
I am able to create a file with ...
Code:
cat < '/dev/null' \ Code:
01 Daniel B. Martin |
Code:
seq -w 10 > $OutFile |
Quote:
Allow me to broaden the question by proposing similar examples. 1) How may I create a new file consisting of six records, with each record containing nine blank characters? 2) How may I create a new file consisting of four records, with each record containing the characters QWERTY? I could use seq to create the file (as you taught) and then sed to substitute other content. Is there a more direct method? Daniel B. Martin |
First thing that springs to mind is awk:
Code:
awk 'BEGIN{for(i=0; i<6; i++) print " "}' Code:
yes ' ' | head -6 |
Or more bash:
Code:
for i in {1..6};do echo " " > file$i;done |
You can do an awful lot in the shell by using combinations of printf, brace expansion, and/or loops.
Code:
#prints numbers 01 to 08, one number per line printf brace expansion |
Thanks to all LQers who posted to this thread.
It's good to see different approaches to solving a problem. Let's mark this one SOLVED! Daniel B. Martin |
oops ... my bad ... just realised it was a single file with multiple columns and not multiple files with a single column :redface:
|
Since I just dug up this old thread for posting elsewhere, I thought I might take the opportunity to add one last trick.
If you want to duplicate a character or string an arbitrary number of times (say from a number contained in a variable), you can use a combination of printf and parameter substitution. Code:
$ n=6 Code:
printf -v line '%*s' "$n" |
All times are GMT -5. The time now is 05:38 PM. |