This post indicates how to insert text in specific lines of a file.
Instead of inserting text I would like to inseart a repetition of a number. For example this series: 2 2 2 2 2 2 2 ... (100 times)
This post indicates how to insert text in specific lines of a file.
Instead of inserting text I would like to inseart a repetition of a number. For example this series: 2 2 2 2 2 2 2 ... (100 times)
Generate the text you'd like inserted:
$ perl -e 'print "2 " x 99, "2\n"' >insert
Insert it into the file (on line 4 in this example):
$ cat file
The
Dog
Is
Here
$ sed '3r insert' file >file.tmp && mv file.tmp file
$ cat file
The
Dog
Is
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
Here
The sed
editing command r
("read") will append the contents of a given file on the next line.
perl -i -pe 'print "2 " x 99, "2\n" if $. == 4' file
.. or if extra space at end is not an issue, perl -i -lpe 'print "2 " x 100 if $. == 4' file
– Sundeep
Feb 21 '17 at 15:20
2 2 2 ...
? Where do you want to insert it? – Satō Katsura Feb 21 '17 at 14:20