Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

How to insert the content of a file into another file?

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #8  
Old Unix and Linux 01-05-2017
RavinderSingh13 RavinderSingh13 is online now Forum Advisor  
Registered User
 
Join Date: May 2013
Last Activity: 23 April 2017, 9:42 AM EDT
Location: Chennai
Posts: 2,430
Thanks: 544
Thanked 1,142 Times in 1,028 Posts
Hello thomasraj87,

As mentioned by RudiC previously, kindly put your requirements all together in a single post with proper sample Input_file and proper expected output_file.

For your current shown files in your previous post, could you please try following and let me know if this helps you.

Code:
awk 'FNR==NR{A[FNR]=$0;next} {print "<tr>" A[FNR] $5 "</td></tr>"}' Input_file1 FS="[><]"  Input_file2

Thanks,
R. Singh
The Following User Says Thank You to RavinderSingh13 For This Useful Post:
thomasraj87 (01-09-2017)
Sponsored Links
    #9  
Old Unix and Linux 01-05-2017
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 23 April 2017, 4:47 AM EDT
Location: Amsterdam
Posts: 11,399
Thanks: 487
Thanked 3,274 Times in 2,889 Posts
Quote:
Originally Posted by RavinderSingh13 View Post
As mentioned by RudiC previously, kindly put your requirements all together in a single post with proper sample Input_file and proper expected output_file.
@OP: And please do this right from the beginning when you start the thread.



--
The example in post #6 should also work with the extra tr tags:

Code:
awk '{p=$0} getline<f>0{$1=$1 p}1' FS='<td>' OFS='<td>' f=file2 file1

The Following User Says Thank You to Scrutinizer For This Useful Post:
thomasraj87 (01-09-2017)
Sponsored Links
    #10  
Old Unix and Linux 01-09-2017
thomasraj87 thomasraj87 is offline
Registered User
 
Join Date: Dec 2011
Last Activity: 10 April 2017, 1:45 AM EDT
Posts: 37
Thanks: 13
Thanked 1 Time in 1 Post
Scrutinizer,

Your code is perfectly working irrespective of number of <tr> tags in a line.

R. Singh,

Code given by you is inserting the <td> tags from 1st file to 2nd file. But it is misplacing the tags and and not printing the rest of the <tr> tags from 2nd file.

Anyhow Thanks all for helping me on this.


Code:
awk 'FNR==NR{A[FNR]=$0;next} {print "<tr>" A[FNR] $5 "</td></tr>"}' file1 FS="[><]" file2


Code:
<tr><td>1</td>text1</td></tr>
<tr><td>2</td>text2</td></tr>
<tr><td>3</td>text3</td></tr>
<tr><td>4</td>text4</td></tr>


Last edited by RudiC; 01-09-2017 at 02:06 PM..
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Insert content of a file right after pattern in another file SkySmart Shell Programming and Scripting 1 11-04-2016 11:01 PM
Insert content of file before the first occurrence of a line starts with a pattern in another file Jagadeesh Kumar Shell Programming and Scripting 14 10-05-2016 11:02 AM
Insert content of a file to another file at a line number which is given by third file Jagadeesh Kumar Shell Programming and Scripting 4 09-29-2016 06:05 AM
Insert content of a file after a certain line in another file ktm Shell Programming and Scripting 4 08-31-2009 05:33 AM



All times are GMT -4. The time now is 09:47 AM.