Sponsored Content
Full Discussion: Match and insert columns
Top Forums UNIX for Dummies Questions & Answers Match and insert columns Post 302887553 by zajtat on Saturday 8th of February 2014 06:07:02 PM
Old 02-08-2014
Match and insert columns

Hi,

I've got two files to match. File one:

HTML Code:
a1 b c d e
a2 b c d e
a3 b c d e
a4 b c d e
and file 2

HTML Code:
a1 1 2 3 4
a2 5 6 7 8
a3 9 10 11 12
a4 1 2 3 4
I need to match them by the first column and add the four columns of file 2 to the file 1 so that those added columns go as columns 4-7

the merged file should look like this:

HTML Code:
a1 b c 1 2 3 4 d e
a2 b c 4 5 6 7 d e
a3 b c 9 10 11 12 d e
a4 b c 1 2 3 4 d e
I've tried matching them with awk, but the merged columns always end up being in the end of the file, not sure how to insert them to the right place.

Many thanks for your time and help in advance!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert text file only after the first match with SED

Hello, I'm new in Shell scripting but i should write a script, which inserts the license header out of a txt-File into the files in our Projekt. For the Java classes it runs without Problems but for XML files not. At xml-files i have to put the license Header after the xml-Header (?xml... (1 Reply)
Discussion started by: PhoenixONE
1 Replies

2. Shell Programming and Scripting

Match and insert in a sorted list

I have a sorted list (python) and I want to insert a string if it matches the pattern in list. Example : Sorted List Above list is in sorted order. I need to insert a name in sorted order and also if the name already exist then it should be inserted before the existing... (1 Reply)
Discussion started by: pratapsingh
1 Replies

3. Shell Programming and Scripting

Match on columns and replace other columns

Hi Friends, I have the following input file cat input chr1 100 200 0.1 0.2 na 1 na nd chr1 105 200 0.1 0.2 1 1 na 98 chr1 110 290 nf 1 na nd na 1 chr2 130 150 12 3 na 1 na 1 chr3 450 600 nf nf na 10 na nd chr4 300 330 1 1 10 11 23 34 My requirement is 1. If $6 is na make $7 nd and... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

4. Shell Programming and Scripting

Evaluate 2 columns, add sum IF two columns match on two rows

Hi all, I know this sounds suspiciously like a homework course; but, it is not. My goal is to take a file, and match my "ID" column to the "Date" column, if those conditions are true, add the total number of minutes worked and place it in this file, while not printing the original rows that I... (6 Replies)
Discussion started by: mtucker6784
6 Replies

5. Shell Programming and Scripting

Request: How to Parse dynamic SQL query to pad extra columns to match the fixed number of columns

Hello All, I have a requirement in which i will be given a sql query as input in a file with dynamic number of columns. For example some times i will get 5 columns, some times 8 columns etc up to 20 columns. So my requirement is to generate a output query which will have 20 columns all the... (7 Replies)
Discussion started by: vikas_trl
7 Replies

6. Shell Programming and Scripting

Sed; insert text two lines above match

Hi! Considering below text, how would I use sed to insert text right below the v0005-line, using the SEPARATOR-line as a pattern to search for, so two lines above the separator? I can do it right above the separator, but not 2 lines... # v0004 - Some text # v0005 - More text #... (5 Replies)
Discussion started by: indo1144
5 Replies

7. Shell Programming and Scripting

Insert Word After Match

Dear ALL, I have sample file : host.txt fullname: FreeBSD Host: server1 ip: 1.1.1.1 mask: 255.255.255.0 fullname: CentOS Host: server2 mask: 255.255.255.0 fullname: Fedora Host: server3 ip: 1.3.1.2 mask: 255.255.255.0 (2 Replies)
Discussion started by: gnulyn
2 Replies

8. Shell Programming and Scripting

Insert file after only first match

i'm using the following code to add the entire content of a file (/tmp/resources.txt) to the line directly below the line containing a pattern (wonderful) in the file mainfile.txt: sed '/^wonderful/ r /tmp/resources.txt' mainfile.txt the problem is, it adds the entire content of... (1 Reply)
Discussion started by: SkySmart
1 Replies

9. Shell Programming and Scripting

Insert text after match in XML file

Having a little trouble getting this to work just right. I have xml files that i want to split some data. I have 2 <name> tags within the file I would like to take only the first tag and split the data. tag example. From this. TAB<Name>smith, john</Name> to TAB<Name>smith,... (8 Replies)
Discussion started by: whegra
8 Replies

10. UNIX for Beginners Questions & Answers

Data match 2 files based on first 2 columns matching only and join if match

Hi, i have 2 files , the data i need to match is in masterfile and i need to pull out column 3 from master if column 1 and 2 match and output entire row to new file I have tried with join and awk and i keep getting blank outputs or same file is there an easier way than what i am... (4 Replies)
Discussion started by: axis88
4 Replies
HTML::TreeBuilder::LibXML(3pm)				User Contributed Perl Documentation			    HTML::TreeBuilder::LibXML(3pm)

NAME
HTML::TreeBuilder::LibXML - HTML::TreeBuilder and XPath compatible interface with libxml SYNOPSIS
use HTML::TreeBuilder::LibXML; my $tree = HTML::TreeBuilder::LibXML->new; $tree->parse($html); $tree->eof; # $tree and $node compatible to HTML::Element my @nodes = $tree->findvalue($xpath); for my $node (@nodes) { print $node->tag; my %attr = $node->all_external_attr; } HTML::TreeBuilder::LibXML->replace_original(); # replace HTML::TreeBuilder::XPath->new DESCRIPTION
HTML::TreeBuilder::XPath is libxml based compatible interface to HTML::TreeBuilder, which could be slow for a large document. HTML::TreeBuilder::LibXML is drop-in-replacement for HTML::TreeBuilder::XPath. This module doesn't implement all of HTML::TreeBuilder and HTML::Element APIs, but enough methods are defined so modules like Web::Scraper work. BENCHMARK
This is a benchmark result by tools/benchmark.pl Web::Scraper: 0.26 HTML::TreeBuilder::XPath: 0.09 HTML::TreeBuilder::LibXML: 0.01_01 Rate no_libxml use_libxml no_libxml 5.45/s -- -94% use_libxml 94.3/s 1632% -- AUTHOR
Tokuhiro Matsuno <tokuhirom slkjfd gmail.com> Tatsuhiko Miyagawa <miyagawa@cpan.org> Masahiro Chiba THANKS TO
woremacx++ http://d.hatena.ne.jp/woremacx/20080202/1201927162 id:dailyflower SEE ALSO
HTML::TreeBuilder, HTML::TreeBuilder::XPath LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-04-02 HTML::TreeBuilder::LibXML(3pm)
All times are GMT -4. The time now is 11:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy