Merging info


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Merging info
# 1  
Old 05-19-2006
Merging info

Hi, pls advise how could we merge contents of lines from 2 different files into 1 file but shares common label continously as in the following example:
Thanks in advance...rgds.

File1:
// line: 0
abc
def
// line: 1
ghi
jkl

File2:
// line: 0
mno
pqr
// line: 1
stu
vwx

End result expected: File3
// line: 0
abc
def
mno
pqr

// line: 1
ghi
jkl
stu
vwx
# 2  
Old 05-19-2006
a try

cp $f1 $tmpf1 #make temp files
cp $f2 $tmpf2 #make temp files
no_list=$(awk '{print $3}' $tmpf1 $tmpf2 |sed '/^$/d'|sort -un)
last_no=$(awk '{print $3}' $tmpf1 $tmpf2 |sed '/^$/d'|sort -un|tail -1)
((last_no=last_no+1))
echo "line: $last_no" >>$tmpf1
echo "line: $last_no" >>$tmpf2
for i in $no_list
do
((nxt=i+1))
print "// line: $i"
sed -n '/line: '$i'/,/line: '$nxt'/p' $tmpf1 $tmpf2|grep -v line
done
rm $tmpf1 $tmpf2 #remove the temp files
This User Gave Thanks to ranj@chn For This Post:
# 3  
Old 05-20-2006
Hi thanks.

But, on unix csh script, the $(awk is giving Illegal variable name...
# 4  
Old 05-20-2006
try back quotes

Try back quotes instead of $(...). I am not sure of the syntax for csh. Someone familiar with csh could help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help on merging

I have a total of 100 files (variable size of each file) with total size of 328950 bytes. I want to merge those 100 files into 4 files with each size be close to equal size i.e (328950/4 ~= 82238) but do not want to break any file. Any unix sheel script help will be really helpful. (18 Replies)
Discussion started by: George1234
18 Replies

2. Shell Programming and Scripting

Merging

Hi, I have searched the forums for a solution but I haven't found a perfect answer, and I'm a bit of a novice, so I hope someone can help: I have 2 files: file1: Chr1 139311 1/1:37,3,0:19 Chr1 139350 1/1:67,6,0:19 Chr1 139404 1/1:0,0,0:7 Chr1 152655 0/1:0,0,0:3 Chr1 152718... (2 Replies)
Discussion started by: ljk
2 Replies

3. Shell Programming and Scripting

Merging two files with merging line by line

Hi, I have two files and i want to merge it like, file1.txt --------- abc cde efg file2.txt ------- 111 222 333 Output file should be, -------------- abc 111 (2 Replies)
Discussion started by: rbalaj16
2 Replies

4. Shell Programming and Scripting

merging

Hi all, I have 2 files. I want to merge a portion or column in file 2 into file 1. file 1 - not tab or space delimited B_1 gihgjfhdj| hgfkddlldjljldjlddl B_2 gihgjddshjgfhs| hgfkddlldjljldjlddl B_3 gihgjfhdj| hgfkddlldjljldjlddlhgjdhdhjdhjhdjhdjhgdj file2 -... (7 Replies)
Discussion started by: Lucky Ali
7 Replies

5. Shell Programming and Scripting

merging two files

Hi everyone, I have two files which will be exactly same at first. After sometime there will be inserts in one file. My problem is how to reflect these changes in second file also. I found out that any compare and merge utility would do the job like, GNU " sdiff " command. But the... (14 Replies)
Discussion started by: rameshonline
14 Replies

6. Shell Programming and Scripting

merging info from 2 files into 1

Hi, I have 2 files that I need to combine. I'm not sure if there is an easy way to use grep or something to combine them how i need. Basically I have 2 csv files. Each file shares an ID for a line of information, but has a bunch of other so I can't easily combine them. file1:... (2 Replies)
Discussion started by: kevin9
2 Replies

7. Shell Programming and Scripting

Merging of rows

Hi guys, Wish you all a very Happy New Year!!!. Thanks in advance. I want to read a file and merge the rows which have '\n' in it. The rows could be > 50,000 bytes. The script should merge all the rows till the next row starts with word 'Type|'. ex.... (24 Replies)
Discussion started by: ssachins
24 Replies

8. Shell Programming and Scripting

Merging 2 files

Hi, I have got two files 1.txt 1111|apple| 2222|orange| 2.txt 1111|1234|000000000004356| 1111|1234|000000001111| 1111|1234|002000011112| 2222|5678|000000002222| 2222|9102|000000002222| I need to merge these two so that my out put looks like below: Search code being used should be... (4 Replies)
Discussion started by: jisha
4 Replies

9. UNIX for Dummies Questions & Answers

Merging two files

Hi I have a requirement like this. I have two files This is how data1.txt looks: EI3171280 38640658501 NENN2005-12-129999-12-312005-12-12HALL NANCY 344 CHENEY HIGHWAY ... (4 Replies)
Discussion started by: venommaker
4 Replies

10. Shell Programming and Scripting

Merging Help

Hi Gurus, I need a help in merging the files. I have nearly 7 files and the files will have time stamp in it. I need to merger these files condition is it is not necessary that all the 7 files has to be there. suppose if i have only 3 files availabe out of these 7 then i need to merge... (3 Replies)
Discussion started by: kumarc
3 Replies
Login or Register to Ask a Question