Content merging at a specific location in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Content merging at a specific location in a file
# 1  
Old 01-04-2013
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.
# 2  
Old 01-04-2013
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.
# 3  
Old 01-04-2013
Hi rudic,
Thanks for the reply.
There is no change in the output,
I mean its not inserting the URLs' .
# 4  
Old 01-05-2013
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert character at specific location in a each line of the file

Hi All, I am trying to write a shell script where it should insert character 'I' in 180th position of each line(except first and last line) of the file. Below is the script for file in /home/test/bharat/*.RET do # Process file echo "File Name=" $file #l_fileName="${file##*/}" ... (19 Replies)
Discussion started by: bharath561989
19 Replies

2. Shell Programming and Scripting

Find and Copy file of specific location

Dear All, I need to transfer all files present in one location to another but those files should be of specific extension like. Find and copy all files of extension .xls, .pdf, .txt from location usr/tmp to location /per/Treat (6 Replies)
Discussion started by: yadavricky
6 Replies

3. Shell Programming and Scripting

Deleting lines in a fixed length file where there is a word at specific location

I have a big file having 100 K lines. I have to read each line and see at 356 character position whethere there is a word "W" in it. If it is their then don't delete the line otherwise delete it. There are two lines as one Header and one trailer which should remain same. Can somebody... (5 Replies)
Discussion started by: mohit kanoongo
5 Replies

4. Shell Programming and Scripting

How to find a word and move it a specific location in xml file using perl?

Hi friends, I have one XML file having below structure :- INput XML file :- <?xml version="1.0" encoding="UTF-8"?> <START> <A=value1> <attr name1="a1"> </A> <B=value2> <attr name2="b1"> <attr name3="c1"> </B> </START> output xml file should be === (3 Replies)
Discussion started by: harpal singh
3 Replies

5. Shell Programming and Scripting

merging of 2 consecutive lines in a file for a specific pattern

Hi , I'm looking for a way to merge two lines only for a given pattern / condition. Input : abcd/dad + -49.201 2.09 -49.5 34 ewrew rewtre * fdsgfds/dsgf/sdfdsfasdd + -4.30 0.62 -49.5 45 sdfdsf cvbbv * sdfds/retret/asdsaddsa + ... (1 Reply)
Discussion started by: novice_man
1 Replies

6. Shell Programming and Scripting

Read Write byte range/chunk of data from specific location in file

I am new to Unix so will really appreciate if someone can guide me on this. What I want to do is: Step1: Read binary file - pick first 2 bytes, convert from hex to decimal. Read the next 3 bytes as well. 2 bytes will specify the number of bytes 'n' that I want to read and write... (1 Reply)
Discussion started by: Kbenipel
1 Replies

7. Shell Programming and Scripting

Bash copy file contents into an existing file at a specific location

Hi all I need to copy the entire contents of one file into an existing file at a specific location. I know the exact line number where I need to put it. It appears I would use either sed or awk to do this, but I have been unsuccessful so far: File A line 1 line 2 line 3 line 4 ... (6 Replies)
Discussion started by: gshepherd7
6 Replies

8. Shell Programming and Scripting

Insert 2 lines in a file at a specific location

Hi, I need to insert two new lines in a file: The file: "..... ...... ULIMIT_MAX_FILES="ulimit -S -n `ulimit -H -n`" .... .... " I need to add the lines: LD_LIBRARY_PATH='$LD_LIBRARY_PATH:$APACHE_HOME/modules' DOWNLOADMODULE_CONF_PATHNAME='$APACHE_HOME/conf/DWLModule.cfg' right... (2 Replies)
Discussion started by: potro
2 Replies

9. Shell Programming and Scripting

Remove duplicates from File from specific location

How can i remove the duplicate lines from a file, for example sample123456Sample testing123456testing XXXXX131323XXXXX YYYYY423432YYYYY fsdfdsf123456gsdfdsd all the duplicates from column 6-12 , must be deleted. I want to consider the first row, if same comes in the given range i want to... (1 Reply)
Discussion started by: gopikgunda
1 Replies

10. Shell Programming and Scripting

Insert lines at specific location in file

Hi There I have this file that I would like to add entries to, however, there is a "}" as the last line that I need to keep. Basically i would like to know how I can write a script that will add new lines at the second to last line position (ie always add new line above the close bracket) ... (17 Replies)
Discussion started by: hcclnoodles
17 Replies
Login or Register to Ask a Question