I have a need to merge two files on the value of an index column.
input file 1
input file 2
output file
I could probably do this in awk, or even with join, but I need to add logic to check each pair of index values to make sure that the data stays in registration. I think this means a higher level language like ruby, python, or perl, but I am not very good with any of those. In most cases, the files will match correctly, but I think I need to add exception handling to check that the files have the same number of rows and that the index values are in the right order.
Can someone point me to a tutorial for one of these languages that shows sample code for loading two files and merging output. I would guess you would hash the column header so you can specify which column is the index. I can do this in excel, but there are 150,000 lines in some of these files and I have allot of them to do.
Can anybody help me out with this problem
" a shell program that takes one or any number of file names as input; sorts the lines of each file in ascending order and displays the non blank lines of each sorted file and merge them as one combined sorted file. The program generates an error... (1 Reply)
Hi
I want to merge two or more files using perl in windows only(Just like Paste command in Unix script) . How can i do this.Is ther any single command to do this?
Thanks
Kunal (1 Reply)
why do inode indices starts from 1 unlike array indexes which starts from 0
its a question from "the design of unix operating system" of maurice j bach
id be glad if i get to know the answer quickly
:) (0 Replies)
Hello,
I have two txt files that look like this:
db.0.0.0.0:
Total number of NS records = 1
db.127.0.0.0:
Total number of NS records = 1
Total number of PTR records = 1
db.172.19.0.0:
Total number of NS records = 1
Total number of PTR records = 3
db.172.19.59.0:
Total... (8 Replies)
Hi,
I have a very basic knowledge of shell scripting & would like some help with a little problem I have. I sometimes use a program calle phronix & sometimes like to compare its results which are *.xml files. Which is easy enough but a friend wants to avoid typing the path to the files.... (2 Replies)
Hi All,
I have a file (FileNames.txt) which contains the following data in it.
$ cat FileNames.txt
MYFILE17XXX208Sep191307.csv
MYFILE19XXX208Sep192124.csv
MYFILE20XXX208Sep192418.csv
MYFILE22XXX208Sep193234.csv
MYFILE21XXX208Sep193018.csv
MYFILE24XXX208Sep194053.csv... (5 Replies)
Hi friends,
I have implemented the merge sort algorith in c, before I put forward my question, you please have a look at my code.
// The array is sorted, as 1234
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int A = {4, 3, 2, 1};
void Merge_Sort(int , int, int);
void... (0 Replies)
Hello,
I have 40 data files where the first three columns are the same (in theory) and the 4th column is different. Here is an example of three files,
file 2: A_f0_r179_pred.txt
Id Group Name E0
1 V N(,)'1 0.2904
2 V N(,)'2 0.3180
3 V N(,)'3 0.3277
4 V N(,)'4 0.3675
5 V N(,)'5 0.3456
... (8 Replies)
Discussion started by: LMHmedchem
8 Replies
LEARN ABOUT PHP
xml_parse_into_struct
XML_PARSE_INTO_STRUCT(3) 1 XML_PARSE_INTO_STRUCT(3)xml_parse_into_struct - Parse XML data into an array structureSYNOPSIS
int xml_parse_into_struct (resource $parser, string $data, array &$values, [array &$index])
DESCRIPTION
This function parses an XML string into 2 parallel array structures, one ($index) containing pointers to the location of the appropriate
values in the $values array. These last two parameters must be passed by reference.
PARAMETERS
o $parser
- A reference to the XML parser.
o $data
- A string containing the XML data.
o $values
- An array containing the values of the XML data
o $index
- An array containing pointers to the location of the appropriate values in the $values.
RETURN VALUES xml_parse_into_struct(3) returns 0 for failure and 1 for success. This is not the same as FALSE and TRUE, be careful with operators such as
===.
EXAMPLES
Below is an example that illustrates the internal structure of the arrays being generated by the function. We use a simple note tag embed-
ded inside a para tag, and then we parse this and print out the structures generated:
Example #1
xml_parse_into_struct(3) example
<?php
$simple = "<para><note>simple note</note></para>";
$p = xml_parser_create();
xml_parse_into_struct($p, $simple, $vals, $index);
xml_parser_free($p);
echo "Index array
";
print_r($index);
echo "
Vals array
";
print_r($vals);
?>
When we run that code, the output will be:
Index array
Array
(
[PARA] => Array
(
[0] => 0
[1] => 2
)
[NOTE] => Array
(
[0] => 1
)
)
Vals array
Array
(
[0] => Array
(
[tag] => PARA
[type] => open
[level] => 1
)
[1] => Array
(
[tag] => NOTE
[type] => complete
[level] => 2
[value] => simple note
)
[2] => Array
(
[tag] => PARA
[type] => close
[level] => 1
)
)
Event-driven parsing (based on the expat library) can get complicated when you have an XML document that is complex. This function does
not produce a DOM style object, but it generates structures amenable of being transversed in a tree fashion. Thus, we can create objects
representing the data in the XML file easily. Let's consider the following XML file representing a small database of aminoacids informa-
tion:
Example #2
moldb.xml - small database of molecular information
<?xml version="1.0"?>
<moldb>
<molecule>
<name>Alanine</name>
<symbol>ala</symbol>
<code>A</code>
<type>hydrophobic</type>
</molecule>
<molecule>
<name>Lysine</name>
<symbol>lys</symbol>
<code>K</code>
<type>charged</type>
</molecule>
</moldb>
And some code to parse the document and generate the appropriate objects:
Example #3
parsemoldb.php - parses moldb.xml into an array of molecular objects
<?php
class AminoAcid {
var $name; // aa name
var $symbol; // three letter symbol
var $code; // one letter code
var $type; // hydrophobic, charged or neutral
function AminoAcid ($aa)
{
foreach ($aa as $k=>$v)
$this->$k = $aa[$k];
}
}
function readDatabase($filename)
{
// read the XML database of aminoacids
$data = implode("", file($filename));
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $data, $values, $tags);
xml_parser_free($parser);
// loop through the structures
foreach ($tags as $key=>$val) {
if ($key == "molecule") {
$molranges = $val;
// each contiguous pair of array entries are the
// lower and upper range for each molecule definition
for ($i=0; $i < count($molranges); $i+=2) {
$offset = $molranges[$i] + 1;
$len = $molranges[$i + 1] - $offset;
$tdb[] = parseMol(array_slice($values, $offset, $len));
}
} else {
continue;
}
}
return $tdb;
}
function parseMol($mvalues)
{
for ($i=0; $i < count($mvalues); $i++) {
$mol[$mvalues[$i]["tag"]] = $mvalues[$i]["value"];
}
return new AminoAcid($mol);
}
$db = readDatabase("moldb.xml");
echo "** Database of AminoAcid objects:
";
print_r($db);
?>
After executing parsemoldb.php, the variable $db contains an array of AminoAcid objects, and the output of the script confirms that:
** Database of AminoAcid objects:
Array
(
[0] => aminoacid Object
(
[name] => Alanine
[symbol] => ala
[code] => A
[type] => hydrophobic
)
[1] => aminoacid Object
(
[name] => Lysine
[symbol] => lys
[code] => K
[type] => charged
)
)
PHP Documentation Group XML_PARSE_INTO_STRUCT(3)