如何在bash中自动使用bash中的字符串的子字符串

时间:2017-04-16 15:37:27

标签: bash shell

我有这两个字符串

<div class="container">
      <div class="jumbotron">
      <?php
        if ( $_SERVER[ "REQUEST_METHOD" ] != "POST" ) {
            $self = $_SERVER[ "PHP_SELF" ];
            ?>
    <form id="search_form" method="post" action="<?php echo $self; ?>" role="form">
          <label>Name</label>
          <input id="companyname" type="text" name="company_name">
          <select id="country" name="country">
        <option value="maine">Maine</option>
      </select>
          <button type="submit">Search</button>
        </form>
        <?php 
        }else{
            $company_name = $_POST["company_name"];
            $country = $_POST["country"];

            switch($country){
                case "maine":
                     echo '<script>console.log("maine")</script>';
                    $url = 'https://icrs.informe.org/nei-sos-icrs/ICRS';
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $company_name);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );   
//              echo '<script>$("#search_form").bind("submit", function() {
// $.ajax({
//   type     : "POST",
//   cache    : false,
//   url      : "https://icrs.informe.org/nei-sos-icrs/ICRS",
//   data     : {WAISqueryString:  $("company_name")},
//   success  : function() {  $("#myIframe").attr("src", "data.responseText") }
// });
// return false;
//});</script>';
                    break;
            }

        }?>
  </div>
    </div>
<div class="col-md-12" style="height:100vh">
      <div id="frame" style="height: 100vh"><iframe id="myIframe" scrolling="no"></iframe> </div>
    </div>

如何输出子串

select     chrom,chromStart,chromEnd,name     from     snp147    where name="NC_0000/22/.11:g./42132048/_/42132049/insTT";

select chrom,chromStart,chromEnd,name from snp147 where name="NC_00000/1/.11:g./42132048/_/42132049/delTT";

正斜杠之间的数字是我想要在子字符串中的数字

我怎样才能在bash中这样做?

1 个答案:

答案 0 :(得分:0)

awk '{ split($6,arry,"/");printf arry[2]"\t"arry[4]"\t"arry[6]"\t"substr(arry[1],6,length(arry[1]))arry[2]substr(arry[3],1,length(arry[3])-2);for(i=4;i<=6;i++) { printf arry[i] };printf substr(arry[7],1,length(arry[7])-1) }' <<< $str1



awk '{ split($6,arry,"/");printf arry[2]"\t"arry[4]"\t"arryarry[6]"\t"substr(arry[1],6,length(arry[1]))arry[2]substr(arry[3],1,length(arry[3])-2);for(i=4;i<=6;i++) { printf arry[i] };printf substr(arry[7],1,length(arry[7])-1) }' <<< $str2

str1是第一个字符串,str2是第二个字符串。我们使用awk和标准空间分隔符拆分字符串。然后,我们使用awk的split函数进一步拆分第6个分隔文本,使用“/”作为分隔符。我们最终在需要时使用制表符打印字符串,并使用子字符串函数打印我们关注的分隔文本部分。