Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Content merging at a specific location in a file

Shell Programming and Scripting


Tags
sathyaonunix

Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-04-2013
Kashyap Kashyap is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 15 October 2013, 5:41 AM EDT
Posts: 24
Thanks: 9
Thanked 0 Times in 0 Posts
Linux Content merging at a specific location in a file

Hi,

This is a bit lengthy problem, i will try to keep explaining it simple.

I have got a file say file1 that contains the following in it,


Code:
------------------------------------------------------------------------ r201463 | ngupta@gmail.com | 2012-06-19 22:02:20 +0530 (Tue, 19 Jun 2012) | 1 line Changed paths: M /client/mb/MBF.java  we press enter key in keypad ------------------------------------------------------------------------ r201464 | ngupta@gmail.com | 2012-06-19 22:04:05 +0530 (Tue, 19 Jun 2012) | 1 line Changed paths: M /client/cvcui/FTC.java M /client/cvcui/RC.java M /client/cvcui/TC.java Screen is cut from above ------------------------------------------------------------------------ r201500 | ssank@gmail.com | 2012-06-20 17:23:33 +0530 (Wed, 20 Jun 2012) | 1 line Changed paths: M /client/mb.ven Cv/mb.ven ------------------------------------------------------------------------ r201535 | asaini@gmail.com | 2012-06-21 05:00:01 +0530 (Thu, 21 Jun 2012) | 1 line Changed paths: M /client/db/RL.java  b3410 ------------------------------------------------------------------------ r201572 | ngupta@gmail.com | 2012-06-21 22:27:37 +0530 (Thu, 21 Jun 2012) | 1 line Changed paths: M /client/mb/res.xml  invalid pin. ------------------------------------------------------------------------ r201575 | ngupta@gmail.com | 2012-06-21 22:45:06 +0530 (Thu, 21 Jun 2012) | 1 line Changed paths: M /client/mb/MBSF.java  UI changes ------------------------------------------------------------------------

Now i have another file say file2

Code:
URL1 xyz/cdd/ddf/client/mb/MBF.java
URL2 xyz/cdd/ddf/client/cvcui/FTC.java
URl3 xyz/cdd/ddf/client/cvcui/RC.java
URL4 xyz/cdd/ddf/client/cvcui/TC.java
URL5 xyz/cdd/ddf/client/mb.ven
URL6 xyz/cdd/ddf/client/db/RL.java
URL7 xyz/cdd/ddf/client/mb/res.xml
URL8 xyz/cdd/ddf/client/mb/MBSF.java

The problem i am facing is i want the links of file 2 to be placed next to the corresponding paths of file1.

The final output i need is as below,

Code:
------------------------------------------------------------------------ r201463 | ngupta@gmail.com | 2012-06-19 22:02:20 +0530 (Tue, 19 Jun 2012) | 1 line Changed paths: M /client/mb/MBF.java URL1 xyz/cdd/ddf/client/mb/MBF.java we press enter key in keypad ------------------------------------------------------------------------ r201464 | ngupta@gmail.com | 2012-06-19 22:04:05 +0530 (Tue, 19 Jun 2012) | 1 line Changed paths: M /client/cvcui/FTC.java URL2 xyz/cdd/ddf/client/cvcui/FTC.java M /client/cvcui/RC.java URl3 xyz/cdd/ddf/client/cvcui/RC.java M /client/cvcui/TC.java URL4 xyz/cdd/ddf/client/cvcui/TC.java Screen is cut from above ------------------------------------------------------------------------ r201500 | ssank@gmail.com | 2012-06-20 17:23:33 +0530 (Wed, 20 Jun 2012) | 1 line Changed paths: M /client/mb.ven URL5 xyz/cdd/ddf/client/mb.ven Cv/mb.ven ------------------------------------------------------------------------ r201535 | asaini@gmail.com | 2012-06-21 05:00:01 +0530 (Thu, 21 Jun 2012) | 1 line Changed paths: M /client/db/RL.java URL6 xyz/cdd/ddf/client/db/RL.java  b3410 ------------------------------------------------------------------------ r201572 | ngupta@gmail.com | 2012-06-21 22:27:37 +0530 (Thu, 21 Jun 2012) | 1 line Changed paths: M /client/mb/res.xml URL7 xyz/cdd/ddf/client/mb/res.xml invalid pin. ------------------------------------------------------------------------ r201575 | ngupta@gmail.com | 2012-06-21 22:45:06 +0530 (Thu, 21 Jun 2012) | 1 line Changed paths: M /client/mb/MBSF.java URL8 xyz/cdd/ddf/client/mb/MBSF.java UI changes ------------------------------------------------------------------------


I hope i have explained the problem.
Please do help me to accomplish this task as i am a newbie to unix.
Thanks,
Manju.
Sponsored Links
    #2  
Old Unix and Linux 01-04-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 3 July 2015, 9:53 AM EDT
Location: Aachen, Germany
Posts: 6,243
Thanks: 109
Thanked 1,700 Times in 1,592 Posts
As you did not specify how to identify the part-URL from file1 in file2,I based it on char position. This may need to be corrected/adapted:
Code:
$ awk 'NR==FNR{Ar[$0]++;next} {for (x in Ar) gsub (substr(x,18), substr(x, 18)" "x)}1' file2 file1

Pls test and come back with results.
Sponsored Links
    #3  
Old Unix and Linux 01-04-2013
Kashyap Kashyap is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 15 October 2013, 5:41 AM EDT
Posts: 24
Thanks: 9
Thanked 0 Times in 0 Posts
Hi rudic,
Thanks for the reply.
There is no change in the output,
I mean its not inserting the URLs' .
    #4  
Old Unix and Linux 01-05-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 3 July 2015, 9:53 AM EDT
Location: Aachen, Germany
Posts: 6,243
Thanks: 109
Thanked 1,700 Times in 1,592 Posts
It does on my linux/nawk system, I compared it to your desired output and it fitted. What system are you on? You may need to run a different version of awk.
Sponsored Links
Closed Linux or Unix Question

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
merging of 2 consecutive lines in a file for a specific pattern novice_man Shell Programming and Scripting 1 12-15-2010 12:47 AM
Bash copy file contents into an existing file at a specific location gshepherd7 Shell Programming and Scripting 6 03-11-2009 09:26 AM
Insert 2 lines in a file at a specific location potro Shell Programming and Scripting 2 05-08-2008 07:38 PM
Remove duplicates from File from specific location gopikgunda Shell Programming and Scripting 1 04-09-2008 02:16 AM
Insert lines at specific location in file hcclnoodles Shell Programming and Scripting 17 03-28-2007 08:00 AM



All times are GMT -4. The time now is 04:26 AM.