Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to write 8 lines from file1 at the beginning of file2.

My file1 contains the following lines:

$BQ  
{ VOL       @home    }  
database    daba  
relation    tcdeatid  
copy           1  
{ version        0 }  
opendb  
clear
# other stuff

My file2 contains the following lines:

.lruno := 72  
.infno := 1    
writedb     
clear

My output file will be:

$BQ  
{ VOL       @home    }  
database    daba  
relation    tcdeatid  
copy           1  
{ version        0 }  
opendb  
clear  
.lruno := 72  
.infno := 1    
writedb       
clear
share|improve this question

4 Answers 4

up vote 2 down vote accepted

You can do it with standard tools.

With paste:

paste -sd'\n' file1 file2

With sed:

sed p file1 file2
share|improve this answer
cat file1 file2 > output_file

Cat is short for concatenate which is what you are trying to do. If you want to keep the results in file1, you could just add them to the end:

cat file2 >> file1

Notice that in the first case output_file will be truncated (using >). Using a double will append (>>)

share|improve this answer

Something like:

head -n8 file1 | cat - file2 > file2."$$" && mv file2."$$" file2
share|improve this answer

With ed

ed file2 <<END
0r file1
w
q
END

at line "0", read in the file "file1", save and exit

As a one-liner: printf "%s\n" "0r file1" w q | ed file2

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.