Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add multiple lines at beginning of file

I have many files within the same subdirectory that looks like:

10 A
11 T
12 A
13 C
15 A

i.e. two columns, where the first line always begins with the number 10.

I would simply like to add lines 1-9 to the beginning of each file i.e.

1
2
3
4
5
6
7
8
9 
10 A
11 T
12 A
13 C
15 A

I don't care about appending the second column.

I know I could do

sed -i '1i1' FILE

to add a first line, but do I have to type this command out for each additional line I want to add?

like image 480
brucezepplin Avatar asked Nov 28 '22 13:11

brucezepplin


1 Answers

Try

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

Where 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
like image 53
thiagowfx Avatar answered Dec 23 '22 10:12

thiagowfx