使用在每个文件的L10字符7-11中找到的值替换多个文件中存在的模式 - UNIX

时间:2015-09-22 12:13:53

标签: unix awk sed

大家好,

我想知道您是否可以帮助我使用UNIX命令/一组命令来修改当前目录中的所有“.mos”文件(其中只包含带文本的行),如下所示: 我想单独替换每个文件“ExternalENodeBFunction = 1”条目“ExternalENodeBFunction = ID

从每个文件的第10行第7-11行读取

ID 。 我知道我可以使用sed命令用其他字符串或awk命令替换模式,但我不知道/理解如何用特定的字符串位置替换。

非常感谢你的帮助,

Catalin

PS我添加了带输入和所需输出的图片

input and  wanted output

输入:

#DoNotEditThisLine: =====================INPUT FILE==================

    gs+
    if $moshell_version ~ ^([7-9]|10)
       l echo "The moshell version is too old. 11.0a or higher is required for scripts containing the crn command."
       return
    fi

    crn ENodeBFunction=1,EUtraNetwork=1,ExternalENodeBFunction=1
    eNBId 42712
    eNodeBPlmnId 
    masterEnbFunctionId
    mfbiSupport 
    userLabel 
    end

    crn ENodeBFunction=1,EUtraNetwork=1,ExternalENodeBFunction=1,ExternalEUtranCellFDD=xxxx
    activePlmnList 
    activeServiceAreaId 
    csgPhysCellId 
    csgPhysCellIdRange 
    eutranFrequencyRef EUtraNetwork=1,EUtranFrequency=1325
    isRemoveAllowed false
    lbEUtranCellOffloadCapacity 
    localCellId
    masterEUtranCellFDDId xxxx
    pciConflict 
    pciConflictCell 
    pciDetectingCell 
    physicalLayerCellIdGroup
    physicalLayerSubCellId 
    tac 
    userLabel xxxx
    end

    crn ENodeBFunction=1,EUtranCellFDD=cell0042753L3,EUtranFreqRelation=1325,EUtranCellRelation=22299-42712-1
    cellIndividualOffsetEUtran 
    coverageIndicator 
    includeInSystemInformation 
    isHoAllowed 
    isRemoveAllowed 
    lbBnrAllowed 
    loadBalancing 
    neighborCellRef EUtraNetwork=1,ExternalENodeBFunction=1,ExternalEUtranCellFDD=xxxx
    qOffsetCellEUtran
    sCellCandidate
    end
    gs-

输出:

        #DoNotEditThisLine: ===============OUTPUT FILE==================

    gs+
    if $moshell_version ~ ^([7-9]|10)
       l echo "The moshell version is too old. 11.0a or higher is required for scripts containing the crn command."
       return
    fi

    crn ENodeBFunction=1,EUtraNetwork=1,ExternalENodeBFunction=42712
    eNBId 42712
    eNodeBPlmnId 
    masterEnbFunctionId
    mfbiSupport 
    userLabel 
    end

    crn ENodeBFunction=1,EUtraNetwork=1,ExternalENodeBFunction=42712,ExternalEUtranCellFDD=xxxx
    activePlmnList 
    activeServiceAreaId 
    csgPhysCellId 
    csgPhysCellIdRange 
    eutranFrequencyRef EUtraNetwork=1,EUtranFrequency=1325
    isRemoveAllowed false
    lbEUtranCellOffloadCapacity 
    localCellId
    masterEUtranCellFDDId xxxx
    pciConflict 
    pciConflictCell 
    pciDetectingCell 
    physicalLayerCellIdGroup
    physicalLayerSubCellId 
    tac 
    userLabel xxxx
    end

    crn ENodeBFunction=1,EUtranCellFDD=cell0042753L3,EUtranFreqRelation=1325,EUtranCellRelation=xxxxx
    cellIndividualOffsetEUtran 
    coverageIndicator 
    includeInSystemInformation 
    isHoAllowed 
    isRemoveAllowed 
    lbBnrAllowed 
    loadBalancing 
    neighborCellRef EUtraNetwork=1,ExternalENodeBFunction=42712,ExternalEUtranCellFDD=xxxx
    qOffsetCellEUtran
    sCellCandidate
    end
    gs-

2 个答案:

答案 0 :(得分:1)

$('body').on('click', '#saveOrderTreeview', function () {
  var html3 = d3.select('.nodeClass')
        .style({"background-color": "White"})
        .attr("version", 1.1)
        .attr("fill","none")
        .attr("stroke-width",1.5)
        .attr("stroke","#ccc")
        .style("font","12px sans-serif") 
        .attr("xmlns", "http://www.w3.org/2000/svg")
        .node().parentNode.innerHTML;
  var name = "orderBook.png";
  var height = ($(".nodeClass").attr("height"));
  var cnvs1 = d3.select("body")
        .append("div")       
        .attr("id", "saveoTreeview")
        .html('<canvas id="mycanvas1" style="display:none" height=' + height + ' width=' + mainChartWidth + '></canvas>');
  var imgsrc = 'data:image/svg+xml;base64,' + window.btoa(unescape(encodeURIComponent(html3)));
  var canvas = document.getElementById("mycanvas1");
  var context = canvas.getContext("2d"); 
  console.log(cnvs1)
  var image = new Image;
  image.src = imgsrc;
  image.onload = function () {
    context.drawImage(image, 0, 0);
    var canvasdata = canvas.toDataURL("image/png");
    var a = document.createElement("a");
    a.download = name;
    a.href = canvasdata;
    document.body.appendChild(a);
    a.click();
  };
}); 
  • 使用此sed的find(或循环中的grep)将为您提供所有想要转换的文件
  • 假设第10行有信息(这里的脚本没有安全,但可能很容易)
  • 需要在内存中加载文件(两次)所以不适合大文件(不知道.mos平均文件大小,希望不是1 Gb)
  • 假设文件未以外部结束更改(可根据需要进行调整),如样本

答案 1 :(得分:1)

你想要的是这样的:

<system.web>
<compilation targetFramework="4.0" debug="true"/>
..........
<authentication mode="Forms">
      <forms loginUrl="login.aspx" name="adAuthCookie" timeout="10" path="/"/>
    </authentication>    
    <identity impersonate="false"/>
    <authorization>
      <deny users="?"/>
      <allow users="*"/>
    </authorization>
</system.web>

但由于您没有提供我们可以测试的任何样本输入/输出,因此它显然未经测试。