基于具有字段中的冗余/缺失值的字段来连接文件

时间:2016-12-20 05:16:47

标签: join field

我有两个制表符分隔的文本文件,我希望基于某个字段(例如,field1)加入。在其中一个文件中,该字段存在冗余,例如:

<!DOCTYPE html>
<html>
<head>
  <title>Contact US</title>
</head>
<body>

<?php
@session_start();
if(isset($_POST['submit'])) {

  if($_SESSION['vcode'] != $_POST['vcode']) {
    $errors = "The characters do not match the captcha code";
  }

  $nombre = $_POST["name"];
  $email    = $_POST["mail"];
  $telefono = $_POST["phone"];
  $mensaje  = $_POST["message"];
    $asunto = "";
    $message = "Usuario:".$_POST['name']." Email:".$_POST['mail']." Telefono ".$_POST['phone']." Informacion ".$_POST['message'];
    $destino = "contacto@example.com";
    $remitente = "From: contacto@example.com";
    mail($destino,$asunto,$message,$remitente);
    unset($_POST['submit']);
    $msg= "Thanks for your comments";
}
?>
<div class="error">
<?php
if(isset($msg)){
  echo "<p class='err'>".$msg."</p>";
}else{
    if(isset($errors) echo $errors;
?>
</div>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" autocomplete="off" enctype="multipart/form-data">
  <div class="touch">
    <div class="name">
      <input type="text" name="name" placeholder="Name" value='' oninvalid="this.setCustomValidity('Please enter your name.')" required>
    </div>
    <div class="email">
      <input type="email" name="mail"  placeholder="Email" value='' title="Please enter your email."  oninvalid="this.setCustomValidity('Please enter your email.')" required>
    </div>
    <div class="phone">
      <input type="tel" name="phone" maxlength="10" pattern="[0-9]{10}" title="Please enter your phone number." oninvalid="this.setCustomValidity('Please enter your phone number.')" placeholder="Phone" value='' required>
    </div>
    <div class="select-pro">
      <select name="producto" oninvalid="this.setCustomValidity('Please Select a product.')"  required>
        <option value="">Select One</option>
        <option value="0">Affair...</option>
        <option value="1">Product 1</option>
        <option value="2">Product 2<option>
        <option value="3">Product 3</option>
        <option value="4">Other</option>
      </select>
    </div>
    <div class="Customer-message">
      <textarea id="message" name="message" title="Please enter your message." placeholder="Su consulta..." oninvalid="this.setCustomValidity('Please enter your message.')"  required></textarea>
    </div>
    <div class="capcha">
      <img src="image.php" name="vcode" id="phoca-captcha"/>
      <input name="vcode" oninvalid="this.setCustomValidity('Please enter captcha.')"  type="text" placeholder="Codigo captcha">
    </div>
      <input type="submit" name="submit" value="Enviar">
  </div>
</form>
<?php } ?>
</body>
</html>

另一方面,没有冗余:

field1  field2  field3
A   gene1   0.01
A   gene2   0.001
A   gene3   0.02
B   gene4   0.01
B   gene5   0.03
C   gene6   0.004

第二个文件还包含第一个文件中不存在的要加入的字段中的值。是否可以使用join命令连接这些文件,以便生成的文件为:

field1  name    pathway
A   A_name  A_pathway
B   B_name  B_pathway
C   C_name  C_pathway
D   D_name  D_pathway
E   E_name  E pathway

我试着查看联接和玩游戏的手册页,但我似乎无法让它工作。

1 个答案:

答案 0 :(得分:1)

由于您对SQLite有一定的了解,因此最有意义的是使用此SQL工具来处理您的问题。首先,使用以下命令将两个CSV文件导入SQLite:

echo $SECRET_KEY_BASE

对第二张表做同样的事情:

sqlite> create table table1 (field1 text, field2 text, field3 real);
sqlite> .separator "\t"
sqlite> .import table1.csv table1

既然您的数据在SQLite中,您可以执行以下简单连接以获得所需的结果集:

sqlite> create table table2 (field1 text, name text, pathway text);
sqlite> .separator "\t"
sqlite> .import table2.csv table2