Bash – Add multiple lines at the beginning of the file

I have many files in the same subdirectory as follows:

10 A
11 T
12 A
13 C
15 A

Two columns, the first line always starts with the number 10.

I just want to Add lines 1-9 at the beginning of each file, that is

123456789 10 A
11 T
12 A
13 C
15 A

I don’t care about appending the second column.

I know I can do it

sed -i ' 1i1' FILE

Add the first line, but do I have to type this command for every other line I want to add?

try

seq 1 9 | cat-file.in> file.out

file.in is the input file you mentioned, and file.out is the name of the desired output file.

Or, even Shorter (thanks @william-pursell):

{ seq 1 9; cat file.in;}> file.out

I have many files in the same subdirectory as follows:

10 A
11 T
12 A< br />13 C
15 A

That is, two columns, where the first line always starts with the number 10.

I just want to add the first line at the beginning of each file. 1-9 lines, i.e.

123456789 10 A
11 T
12 A
13 C
15 A

I don’t care about appending the second column.

I know I can do it

sed -i '1i1' FILE

Add the first line, but do I have to type this command for every other line I want to add?

Try

seq 1 9 | cat-file.in> file.out< /pre> 

file.in is the input file you mentioned, and file.out is the name of the desired output file.

Or, even shorter (thanks @william-pursell):

p>

{ seq 1 9; cat file.in;}> file.out

Leave a Comment

Your email address will not be published.