adding the content of a file to another file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting adding the content of a file to another file
# 1  
Old 08-19-2008
adding the content of a file to another file

Hi everyone,
I am trying to search for a pattern(in this case copyright) in file A and then add the content of file B under the pattern(copyright) found in file A

i did the following

set var=`cat ~/b`
sed "/copyright/ a\${var}" ~/a

this does it job partially because it does not keep the format of file b. for some reason the new lines are being ignored and all the input of file b are written back to back under the pattern"copyright"

is there anyone who could help me with this?
# 2  
Old 08-19-2008
Use the r command of sed to insert the file:

Code:
sed '/copyright/r fileB' fileA

Regards
# 3  
Old 08-19-2008
thanks alot for the command but i think there is something wrong with what you wrote here because it does not really wrok
# 4  
Old 08-19-2008
sed '/copyright/r fileB' fileA >fileC

works for me

check this: Sed - An Introduction and Tutorial
# 5  
Old 08-19-2008
yes
i am really sorry for that. it works just fine, and i also saw the same thing on sed tutorial.
Once again i appreciate your help...
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert content of a file to another file at a line number which is given by third file

Hi friends, here is my problem. I have three files like this.. cat file1.txt ======= unix is best unix is best linux is best unix is best linux is best linux is best unix is best unix is best cat file2.txt ======== Windows performs better Mac OS performs better Windows... (4 Replies)
Discussion started by: Jagadeesh Kumar
4 Replies

2. Shell Programming and Scripting

How to remove exisiting file content from a file and have to append new file content?

hi all, i had the below script x=`cat input.txt |wc -1` awk 'NR>1 && NR<'$x' ' input.txt > output.txt by using above script i am able to remove the head and tail part from the input file and able to append the output to the output.txt but if i run it for second time the output is... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

3. Shell Programming and Scripting

Change the file name and copy old file content to new file names.

Hi, I have a files in a directory as below :- ls -1 mqdepth-S1STC02 proc-mq-S1STC01 proc-mq-S1STC02 proc-mq-S1STC03 Whereever i have S1STC i need to copy them into new file with file name S2STC. expected output :- ls -1 mqdepth-S2STC02 proc-mq-S2STC01 proc-mq-S2STC02... (3 Replies)
Discussion started by: satishmallidi
3 Replies

4. Shell Programming and Scripting

Sed: replace content from file with the content from file

Hi, I am having trouble while using 'sed' with reading files. Please help. I have 3 files. File A, file B and file C. I want to find content of file B in file A and replace it by content in file C. Thanks a lot!! Here is a sample of my question. e.g. (file A: a.txt; file B: b.txt; file... (3 Replies)
Discussion started by: dirkaulo
3 Replies

5. Shell Programming and Scripting

Adding content of two file in a single file column wise

Hi, I am trying to get the file in particular pattern using shell script. I have to add one column to some other file. For example consider two file as below. File1: name1 name2 name3 File2: Add1 age1 Add2 age2 Add3 age3 I want this two file in a single file format something like... (3 Replies)
Discussion started by: diehard
3 Replies

6. UNIX for Dummies Questions & Answers

Adding the content of file in another one...

This might be a weird question, that's not possible, but just wondering: If I have a file for example that has the content: awk '{print "head - "$1" > reduce_lines_"$1}' all And another file that has the content: 221 Is there a way to put the 221 in the space (after head -) of... (27 Replies)
Discussion started by: cosmologist
27 Replies

7. Shell Programming and Scripting

Need help with awk - how to read a content of a file from every file from file list

Hi Experts. I need to list the file and the filename comes from the file ListOfFile.txt. Basicly I have a filename "ListOfFile.txt" and it contain Example of ListOfFile.txt /home/Dave/Program/Tran1.P /home/Dave/Program/Tran2.P /home/Dave/Program/Tran3.P /home/Dave/Program/Tran4.P... (7 Replies)
Discussion started by: tanit
7 Replies

8. Shell Programming and Scripting

adding the content of a file to another file

hi guys, I posted a similar question about reading a file and adding its content to another file and i used sed '/HELLO/r fileB' fileA however this command adds the content of fileB under the word "HELLO" what if i need to add the word above "HELLO". what could i use? Thanks, (6 Replies)
Discussion started by: ROOZ
6 Replies

9. Shell Programming and Scripting

Adding filename into file content

Dear Experts, Please help to teach me how to add the filename into the file content. Actually the file name are EVENTS-20050912. ***************New output that I want*************** EVENTS-20050912 03:33:37 ALARM: BTSSPAN-277-1 30-18013 EVENTS-20050912 12:10:28 ALARM: BTSSPAN-297-2... (1 Reply)
Discussion started by: missutoomuch
1 Replies
Login or Register to Ask a Question