Sponsored Content
Full Discussion: merging two files
Top Forums Shell Programming and Scripting merging two files Post 52920 by Gary Dunn on Tuesday 29th of June 2004 05:35:27 PM
Old 06-29-2004
making things too hard

hello,

there are many ways to skin a cat. All good suggestions, however, the file cannot be sorted. One of the files will only have appended data , meaning the data is attached to the end of the file only. The other file will have data inserts that could appear all over the file. From the example given:

file1

this is mango
this is banana
this is apple
this is grape
this is pineapple
this is orange
this is watermelon

file2

this is mango
this is apple
this is orange
this is cherry
this is lemon

OUTPUT should be

this is mango
this is banana
this is apple
this is grape
this is pineapple
this is orange
this is watermelon
this is cherry
this is lemon

----------------------------------

the one solution given by appending the second file appears to be what you want. That is if this example holds true. The implementation needs a little going over.

If only one file, file1 will have modified data inserts all over its contents. This can be your primary file.
The second file does not really need to start off with any content since the only data modifications to be performed are to be done on the EOF. New data appended to back of file.
If you want to keep a copy of the original file then simply have three (3) files instead of two (2)

When the event happens that you merge these files say a specific time sceduled in cron or by size or what ever it is you simply take the 3rd files contents , which are the records originally appended to the back of the secondary file. ( which now is just a copy of the original file ) a 3rd file has the new records.
then simply append file2 to file1.


--------------------
original data
----
this is mango
this is apple
this is orange

--------------------
file 1 & file 2 look like

this is mango
this is apple
this is orange
-------------------------
file 3
null
-------------------------
file1 after inserts

this is mango
this is banana
this is apple
this is grape
this is pineapple
this is orange
this is watermelon

file2-----------------
simply a copy or dummy file showing appends
- don't really need except for archive purposes

this is mango
this is apple
this is orange
[this is cherry]
[this is lemon]

-------------------------------------
3rd / ( or 2nd ) file
this is cherry
this is lemon

OUTPUT file ( cat file2 >> file1 )

this is mango
this is banana
this is apple
this is grape
this is pineapple
this is orange
this is watermelon
this is cherry
this is lemon


Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

merging files

Thanks in advance I have 2 files having key field in each.I would like to join both on common key.I have used join but not sucessful. The files are attached here . what i Want in the output is on the key field SLS OFFR . I have used join commd but not successful. File one ======= SNO ... (6 Replies)
Discussion started by: vakharia Mahesh
6 Replies

2. 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

3. Shell Programming and Scripting

Help with merging files

i would like to merge two files that have the same format but have different data. i would like to create one output file that contains information from both the original files.:rolleyes: (2 Replies)
Discussion started by: joe black
2 Replies

4. Shell Programming and Scripting

merging of files.

Hi, I want to merge the two files on the basis of columns like... file 1 Data Key A 12 B 13 file2 Data Value A A1 A A2 B B1 B B2 (5 Replies)
Discussion started by: clx
5 Replies

5. UNIX for Dummies Questions & Answers

Merging two files

Hi, I have two files a.txt and b.txt. a.txt 1 2 3 4 b.txt a b c d e I want to generate a file c.txt by merging these two file and the resultant file would contain c.txt 1 (4 Replies)
Discussion started by: siba.s.nayak
4 Replies

6. Shell Programming and Scripting

Merging files

I have two files file 1 containing x rows and 1 column file 2 containing x rows and 1 column I want to merge both the files and add a comma between the two eg plz guide (1 Reply)
Discussion started by: test_user
1 Replies

7. Shell Programming and Scripting

Merging two files with same name

Hello all, I have limited experience in shell scripting. Here goes my question: I have two directories that have same number of files with same file names i.e. consider 2 directories A and B. Both directories have files 1.txt, 2.txt...... I need to merge the file 1.txt of A with file 1.txt... (5 Replies)
Discussion started by: jaysean
5 Replies

8. Shell Programming and Scripting

Help with merging 2 files into 1

::::::::: ::FileA:: ::::::::: A1-------A2--------A3---A4---A5-- ================================= AC5VXVLT-XX---------------------- B57E434--XXXX1-----MMMM-ZZZ--111- C325G20--XXXXX3----CCCC------3332 DC35S51--XXXXY1----DDDD------44X- DC35S52--XXXXY2----DDDD------44Y-... (5 Replies)
Discussion started by: lordsmiter
5 Replies

9. Shell Programming and Scripting

Merging two files

Guys, I am having little problem with getting a daily report! The daily process that I do is as follows 1. Unload Header for the report from the systables to one unl file, say Header.unl 2. Unload the data from the required table/tables to another unl file, say Data.unl 3. Send a... (2 Replies)
Discussion started by: PikK45
2 Replies

10. Shell Programming and Scripting

Merging two files

Hi All , I have a scenario where we need to combine two files . Below are the sample files and expected output , File 1: 1|ab 1|ac 1|ae 2|ad 2|ac File 2: 1|xy 1|fc 2|gh 2|ku Output file : 1|ab|xy (3 Replies)
Discussion started by: saj
3 Replies
ARRAY_PUSH(3)								 1							     ARRAY_PUSH(3)

array_push - Push one or more elements onto the end of array

SYNOPSIS
int array_push (array &$array, mixed $value1, [mixed $...]) DESCRIPTION
array_push(3) treats $array as a stack, and pushes the passed variables onto the end of $array. The length of $array increases by the num- ber of variables pushed. Has the same effect as: <?php $array[] = $var; ?> Note If you use array_push(3) to add one element to the array it's better to use $array[] = because in that way there is no overhead of calling a function. Note array_push(3) will raise a warning if the first argument is not an array. This differs from the $var[] behaviour where a new array is created. PARAMETERS
o $array - The input array. o $value1 - The first value to push onto the end of the $array. RETURN VALUES
Returns the new number of elements in the array. EXAMPLES
Example #1 array_push(3) example <?php $stack = array("orange", "banana"); array_push($stack, "apple", "raspberry"); print_r($stack); ?> The above example will output: Array ( [0] => orange [1] => banana [2] => apple [3] => raspberry ) SEE ALSO
array_pop(3), array_shift(3), array_unshift(3). PHP Documentation Group ARRAY_PUSH(3)
All times are GMT -4. The time now is 11:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy