Sponsored Content
Top Forums Shell Programming and Scripting Merge of two input file by search Post 302588242 by birei on Saturday 7th of January 2012 06:53:49 PM
Old 01-07-2012
Hi kykyboss,

One way:
Code:
$ cat file1
D33963|BNS Default Swap|-261564.923909249|
D24484|BNS Default Swap|-53356.6868058492|
D24485|BNS Default Swap|-21180.9904679111|
D33965|BNS Default Swap|154181.478745804|
D24486|BNS Default Swap|-47413.0013193052|
D33966|BNS Default Swap|-154181.478745804|
D24487|BNS Default Swap|-63253.9807711966|
D33968|BNS Default Swap|-160521.81007754|
D24489|BNS Default Swap|-10584.4665849774|
S85801|BNS Swap|451309.300774646|
D33969|BNS Default Swap|118166.419991555|
$ cat file2
:E00277,48089,,,Trading,FALSE,,CAISSE,19189,AA,CAD
:D24485,48085,,,Trading,FALSE,,CASSE,19139,AA,CAD
:D2448,48083,,,Trading,FALSE,,CAIE,19029,AA,CAD
:D33963,48082,,,Trading,FALSE,,CAISSE,19149,AA,CAD,
:E00286CAP,48082,,,Trading,FALSE,,CAISSE,19149,AA,CAD
$ cat script.pl
use warnings;
use strict;

die qq[Usage: perl $0 <file1> <file2>\n] unless @ARGV == 2;

open my $fh1, "<", shift @ARGV or die qq[Error: Cannot open input file\n];
open my $fh2, "<", shift @ARGV or die qq[Error: Cannot open input file\n];

my (%file1);

while ( my $line = <$fh1> ) {
        chomp $line;
        my ($field1, $rest) = split /\|/, $line, 2;
        $file1{ $field1 } = $line;
}

while ( my $line = <$fh2> ) {
        chomp $line;
        for ( keys %file1 ) {
                if ( index( $line, $_ ) > -1 ) {
                        printf qq[%s%s\n], $file1{ $_ }, $line =~ s/,/|/gr;
                        last;
                }
        }

}
$ perl script.pl file1 file2
D24485|BNS Default Swap|-21180.9904679111|:D24485|48085|||Trading|FALSE||CASSE|19139|AA|CAD
D33963|BNS Default Swap|-261564.923909249|:D33963|48082|||Trading|FALSE||CAISSE|19149|AA|CAD|

Regards,
Birei
This User Gave Thanks to birei For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

search file, change existing value based on input (awk help)

I have a file (status.file) of the form: valueA 3450 valueB -20 valueC -340 valueD 48 I am tailing a data.file, and need to search and modify a value in status.file...the tail is: tail -f data.file | awk '{ print $3, ($NF - $(NF-1)) }' which will produce lines that look like this: ... (3 Replies)
Discussion started by: nortonloaf
3 Replies

2. Shell Programming and Scripting

Using an input (?) file to search another

I have a file (DCN.txt) that has about 35000 lines. It looks like: 10004470028 10005470984 10006470301 10007474812 .... I have several other files (a11.txt, a12.txt, a12_1.txt, a13.txt, etc. about 70, each 100 mb large) that have history records like so: LINE 10005470984 01/06/2010... (13 Replies)
Discussion started by: oriqin
13 Replies

3. Solaris

Keyword search input from a file

Hi, I have a file which got only one column and got some keywords. I have another file where the keywords used in the first file are repeated in the second file. Now I would like to know how many times each keyword from the first file is repeated in the second file. Request your help on... (1 Reply)
Discussion started by: pointers
1 Replies

4. Shell Programming and Scripting

Read input files and merge them in given order and write them to input one param or one file

Dear Friends, I am looking for a shell script to merge input files into one file .. here is my idea: 1st paramter would be outfile file (all input files content) read all input files and merge them to input param 1 ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
Discussion started by: hyd1234
4 Replies

5. Shell Programming and Scripting

Bash to search file based off user input then create new file

In the below bash a file is downloaded when the program is opened and then that file is searched based on user input and the result is written to a new file. For example, the bash is opened and the download.txt is downloaded, the user then enters the id (NA04520). The id is used to search... (5 Replies)
Discussion started by: cmccabe
5 Replies

6. Shell Programming and Scripting

UNIX Scripting help to input string and search a file to find

Hi everyone, I am new to Unix and need help writing a script that can ask user for an input, then search that input within a file I know will have to use the read and grep commands, anyone can give me somewhere to start would help Task: Write a script to display which volume pool a given... (1 Reply)
Discussion started by: 12ic11
1 Replies

7. Shell Programming and Scripting

UNIX Scripting help to input string and search a file to find

Hi Don, this is not homework question. I work for a Credit card company and my development goal this year is to learn Unix. I would love if others can help me get started, thanks. Hi everyone I am new to Unix and need help writing a script that can ask user for an input, then search that input... (2 Replies)
Discussion started by: 12ic11
2 Replies

8. Linux

Search a template file and replace with input

Hi I have a CommonTemplateStop.template file . Inside the file i need to replace the variables DepName and CompInsName with the values(Trade and TradeIns) specified in the script. I have written the below .sh script in linux server which will read the .template file and has to replace the 2... (8 Replies)
Discussion started by: samrat dutta
8 Replies

9. Shell Programming and Scripting

Search pattern in a file taking input from another file

Hi, Below is my requirement File1: svasjsdhvassdvasdhhgvasddhvasdhasdjhvasdjsahvasdjvdasjdvvsadjhv vdjvsdjasvdasdjbasdjbasdjhasbdasjhdbjheasbdasjdsajhbjasbjasbhddjb svfsdhgvfdshgvfsdhfvsdadhfvsajhvasjdhvsajhdvsadjvhasjhdvjhsadjahs File2: sdh hgv I need a command such that... (8 Replies)
Discussion started by: imrandec85
8 Replies

10. UNIX for Beginners Questions & Answers

Reducing input file size after pattern search

I have a very large file with millions of entries identified by @M. I am using the following script to "extract" entries based on specific strings/patterns: #!/bin/bash if ] then file=$1 else echo "Input_file passed as an argument $1 is NOT found." exit; fi MID=(NULL "string-1"... (10 Replies)
Discussion started by: Xterra
10 Replies
elographics(4)						     Kernel Interfaces Manual						    elographics(4)

NAME
elographics - Elographics input driver SYNOPSIS
Section "InputDevice" Identifier "idevname" Driver "elographics" Option "Device" "devpath" ... EndSection DESCRIPTION
elographics is an Xorg input driver for Elographics touchscreen devices. The elographics driver functions as a pointer input device, and may be used as the X server's core pointer. SUPPORTED HARDWARE
E271-2210 and E271-2200 devices are supported. E281-2310 and compatible devices are supported with some features unavailable. CONFIGURATION DETAILS
Please refer to xorg.conf(5) for general configuration details and for options that can be used with all input drivers. This section only covers configuration details specific to this driver. The following driver options are supported: Option "Device" "string" The device that is attached to the touchscreen interface. Default is "/dev/ttyS1". Option "MinX" "integer" Set the minimum value for the touchscreen X axis. Default is 600. Option "MaxX" "integer" Set the maximum value for the touchscreen X axis. Default is 3000. Option "MinY" "integer" Set the minimum value for the touchscreen Y axis. Default is 600. Option "MaxY" "integer" Set the maximum value for the touchscreen Y axis. Default is 3000. Option "ScreenNo" "integer" The screen to attach to the touchscreen when running with multiple screens. Default is screen 0. Option "PortraitMode" "string" Set the X/Y axis orientation. The default is "Landscape" but you can rotate clockwise ("Portrait") or counter-clockwise ("Por- traitCCW"). Option "SwapXY" "boolean" Swap the X and Y axis on the display. Default is false. Option "UntouchDelay" "integer" The period that finger must be released for an untouch event to occur. Default: 5 (50ms). Option "ReportDelay" "integer" Delay between report packets. Default: 1 (10ms). Option "Model" "string" The touchscreen model. Default: unset. Supported models: "Sunit dSeries". SEE ALSO
Xorg(1), xorg.conf(5), Xserver(1), X(7). AUTHORS
Authors include: Patrick Lecoanet This manpage was written by Lee Maguire on behalf of the Debian Project. X Version 11 xf86-input-elographics 1.4.1 elographics(4)
All times are GMT -4. The time now is 07:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy