Sponsored Content
Full Discussion: Merge column file
Top Forums Shell Programming and Scripting Merge column file Post 302931781 by MadeInGermany on Thursday 15th of January 2015 11:29:36 AM
Old 01-15-2015
Lightbulb

Here is a general merge
Code:
#!/bin/sh
while     
 read line2 <&4
 e2=$?
 read line1 <&3 || [ $e2 -eq 0 ]
do
 if [ -z "$line1" ]
 then
  while read line2 <&4 && [ -n "$line2" ]
  do
   printf "%s\n" "$line2"
  done 
 elif [ -z "$line2" ]
 then
  while read line1 <&3 && [ -n "$line1" ]
  do
   printf "%s\n" "$line1"
  done 
 fi
 printf "%s\n" "$line1 $line2"
done 3<file1 4<file2

This User Gave Thanks to MadeInGermany For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Column Merge?

Hi all, I need to join two columns from two different files file1.txt and file2.txt and append in a new file. Example : $cat file1.txt ABCD.ksh:010141 ABCD.ksh:010511 ABCD.ksh:010815 ABCD.ksh:011114 ABCD.ksh:011415 ABCD.ksh:011720 ABCD.ksh:012022 ABCD.ksh:012830 ABCD.ksh:014432... (5 Replies)
Discussion started by: sabyasm
5 Replies

2. Shell Programming and Scripting

Merge Two Files based on First column

Hi, I need to join two files based on first column of both files.If first column of first file matches with the first column of second file, then the lines should be merged together and go for next line to check. It is something like: File one: 110001 abc efd 110002 fgh dfg 110003 ... (10 Replies)
Discussion started by: apjneeraj
10 Replies

3. Shell Programming and Scripting

merge two two txt files into one file based on one column

Hi, I have file1.txt and file2.txt and would like to create file3.txt based on one column in UNIX Eg: file1.txt 17328756,0000786623.pdf,0000786623 20115537,0000793892.pdf,0000793892 file2.txt 12521_74_4.zip,0000786623.pdf 12521_15_5.zip,0000793892.pdf Desired Output ... (5 Replies)
Discussion started by: techmoris
5 Replies

4. Shell Programming and Scripting

Help with merge two file based on similar column content

Input file 1: A1BG A1BG A1BG A1CF A1CF BCAS BCAS A2LD1 A2M A2M HAT . . Input file 2: A1BG All A1CF TEMP (5 Replies)
Discussion started by: perl_beginner
5 Replies

5. Shell Programming and Scripting

Merge CSV files and create a column with the filename from the original file

Hello everyone!! I am not completely new to shell script but I havent been able to find the answer to my problem and I'm sure there are some smart brains here up for the challenge :D. I have several CSV files that I need to combine into one, but I also need to know where each row came from.... (7 Replies)
Discussion started by: fransanchezoria
7 Replies

6. Shell Programming and Scripting

column merge same value

Dear All, I have the following file: file1 "1" 189218400 189221399 3000 "0041 ENSMUSG00000000031" "0041" "+" "ENSMUSG00000000031" 189039418 189175306 "downstream" 178982 43094 "NearestStart" "1" 197067200 197068353 1154 "0057... (3 Replies)
Discussion started by: paolo.kunder
3 Replies

7. Shell Programming and Scripting

Merge with common column

hi i have two files and i wanted to join them using common column. try to do this using "join" command but that did not help. File 1: 123 9a.vcf hy92.vcf hy90.vcf Index Ref Alt Ref Alt Ref Alt 315 14 0 7 4 ... (6 Replies)
Discussion started by: empyrean
6 Replies

8. Shell Programming and Scripting

Multiple file merge by column

Hello all, I am quite new in linux shell scripting and I have this issue. I ve got some files including measurements taken every 10minutes for a whole day. File name format is: 00.00, 00.10, 00.20,....23.50 File structure is: x | y | temperature x and y is the same in all files (same... (12 Replies)
Discussion started by: atzounis
12 Replies

9. Shell Programming and Scripting

Seperated by columns, merge in a file, sort them on common column

Hi All, I have 4 files in below format. I took them as an example. File 1: Cut from position 1-4 then 6-7 then 8-14 then rest left and make them as columns in one new file. Inserting character H to the initial of all line like HCTOT. CTOT 456787897 Low fever CTOR 556712345 High fever... (2 Replies)
Discussion started by: Mannu2525
2 Replies

10. UNIX for Beginners Questions & Answers

Cut specific column from 2 file and merge

Hi ALL, I have two file. I need to combine these two file based on a layout. I used the below code and able to extract the record. But now able to insert that to a 3'rd file in between the extract FILE 1 CAID NUMBER 1-20 TID NUMBER 21-22 LABEL CHAR 23-44 BASE 45-60... (5 Replies)
Discussion started by: arunkumar_mca
5 Replies
Async::MergePoint(3pm)					User Contributed Perl Documentation				    Async::MergePoint(3pm)

NAME
"Async::MergePoint" - resynchronise diverged control flow SYNOPSIS
use Async::MergePoint; my $merge = Async::MergePoint->new( needs => [ "leaves", "water" ], ); my $water; Kettle->boil( on_boiled => sub { $water = shift; $merge->done( "water" ); } ); my $tea_leaves; Cupboard->get_tea_leaves( on_fetched => sub { $tea_leaves = shift; $merge->done( "leaves" ); } ); $merge->close( on_finished => sub { # Make tea using $water and $tea_leaves } ); DESCRIPTION
Often in program logic, multiple different steps need to be taken that are independent of each other, but their total result is needed before the next step can be taken. In synchonous code, the usual approach is to do them sequentially. An asynchronous or event-based program could do this, but if each step involves some IO idle time, better overall performance can often be gained by running the steps in parallel. A "Async::MergePoint" object can then be used to wait for all of the steps to complete, before passing the combined result of each step on to the next stage. A merge point maintains a set of outstanding operations it is waiting on; these are arbitrary string values provided at the object's construction. Each time the "done()" method is called, the named item is marked as being complete. When all of the required items are so marked, the "on_finished" continuation is invoked. For use cases where code may be split across several different lexical scopes, it may not be convenient or possible to share a lexical variable, to pass on the result of some asynchronous operation. In these cases, when an item is marked as complete a value can also be provided which contains the results of that step. The "on_finished" callback is passed a hash (in list form, rather than by reference) of the collected item values. This module was originally part of the IO::Async distribution, but was removed under the inspiration of Pedro Melo's Async::Hooks distribution, because it doesn't itself contain anything IO-specific. CONSTRUCTOR
$merge = Async::MergePoint->new( %params ) This function returns a new instance of a "Async::MergePoint" object. The %params hash takes the following keys: needs => ARRAY Optional. An array containing unique item names to wait on. The order of this array is not significant. on_finished => CODE Optional. CODE reference to the continuation for when the merge point becomes ready. If provided, will be passed to the "close" method. METHODS
$merge->close( %params ) Allows an "on_finished" continuation to be set if one was not provided to the constructor. on_finished => CODE CODE reference to the continuation for when the merge point becomes ready. The "on_finished" continuation will be called when every key in the "needs" list has been notified by the "done()" method. It will be called as $on_finished->( %items ) where the %items hash will contain the item names that were waited on, and the values passed to the "done()" method for each one. Note that this is passed as a list, not as a HASH reference. While this feature can be used to pass data from the component parts back up into the continuation, it may be more direct to use normal lexical variables instead. This method allows the continuation to be placed after the blocks of code that execute the component parts, so it reads downwards, and may make it more readable. $merge->needs( @keys ) When called on an open MergePoint (i.e. one that does not yet have an "on_finished" continuation), this method adds extra key names to the set of outstanding names. The order of this list is not significant. This method throws an exception if the MergePoint is already closed. $merge->done( $item, $value ) This method informs the merge point that the $item is now ready, and passes it a value to store, to be passed into the "on_finished" continuation. If this call gives the final remaining item being waited for, the "on_finished" continuation is called within it, and the method will not return until it has completed. EXAMPLES
Asynchronous Plugins Consider a program using "Module::Pluggable" to provide a plugin architecture to respond to events, where sometimes the response to an event may require asynchronous work. A "MergePoint" object can be used to coordinate the responses from the plugins to this event. my $merge = Async::MergePoint->new(); foreach my $plugin ( $self->plugins ) { $plugin->handle_event( "event", $merge, @args ); } $merge->close( on_finished => sub { my %results = @_; print "All plugins have recognised $event "; } ); Each plugin that wishes to handle the event can use its own package name, for example, as its unique key name for the MergePoint. A plugin handling the event synchonously could perform something such as: sub handle_event { my ( $event, $merge, @args ) = @_; .... $merge->needs( __PACKAGE__ ); $merge->done( __PACKAGE__ => $result ); } Whereas, to handle the event asynchronously the plugin can instead perform: sub handle_event { my ( $event, $merge, @args ) = @_; .... $merge->needs( __PACKAGE__ ); sometime_later( sub { $merge->done( __PACKAGE__ => $result ); } ); } AUTHOR
Paul Evans <leonerd@leonerd.org.uk> perl v5.12.3 2011-06-10 Async::MergePoint(3pm)
All times are GMT -4. The time now is 09:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy