我无法使用Shell脚本替换文件中的内容

时间:2018-08-23 13:01:35

标签: shell replace scripting

(function(){})(); window.getJetPaths = function(b){var c = {knockout:“ / emsaasui / uifwk / libs / 4.2.0-41239.001032001 / js / oraclejet / js / libs / knockout / knockout-3.4.0”,“ knockout.mapping “:” / emsaasui / uifwk / libs / 4.2.0-41239.001032001 / js / oraclejet / js / libs / knockout / knockout.mapping-latest“,jquery:” / emsaasui / uifwk / libs / 4.2.0-41239.001032001 / js /oraclejet/js/libs/jquery/jquery.min",jqueryui:"/emsaasui/uifwk/libs/4.2.0-41239.001032001/js/oraclejet/js/libs/jquery/jquery-ui-1.12.0.custom。 min“,” jqueryui-amd“:” / emsaasui / uifwk / libs / 4.2.0-41239.001032001 / js / oraclejet / js / libs / jquery / jqueryui-amd-1.12.0.min“,承诺:” / emsaasui / uifwk / libs / 4.2.0-41239.001032001 / js / oraclejet / js / libs / es6-promise / es6-promise.min“, 要求:“ / emsaasui / uifwk / libs / 4.2.0-41239.001032001 / js / oraclejet / js / libs / require / require”,hammerjs:“ / emsaasui / uifwk / libs / 4.2.0-41239.001032001 / js / oraclejet / js /libs/hammer/hammer-2.0.8.min",ojs:"/emsaasui/uifwk/libs/4.2.0-41239.001032001/js/oraclejet/js/libs/oj/v4.2.0/min",ojL10n:“ /emsaasui/uifwk/libs/4.2.0-41239.001032001/js/oraclejet/js/libs/oj/v4.2.0/ojL10n",ojtranslations:"/emsaasui/uifwk/libs/4.2.0-41239.001032001/js/oraclejet/ js / libs / oj / v4.2.0 / resources“,ojdnd:” / emsaasui / uifwk / libs / 4.2.0-41239.001032001 / js / oraclejet / js / libs / dnd-polyfill / dnd-polyfill-1.0.0.min ”, 信号:“ / emsaasui / uifwk / libs / 4.2.0-41239.001032001 / js / oraclejet / js / libs / js-signals / signals.min”,customElements:“ / emsaasui / uifwk / libs / 4.2.0-41239.001032001 / js /oraclejet/js/libs/webcomponents/custom-elements.min“,十字路口:空,历史记录:空,文本:” / emsaasui / uifwk / libs / 4.2.0-41239.001032001 / js / oraclejet / js / libs / require / text“},a; for(a in c)c [a]?b [a] = c [a]:delete b [a]; return b}; window.getJetBundles = function(){返回window.isDevMode?[]:“ customElements Hammerjs jqueryui jqueryui-amd jqueryui-amd / data jqueryui-amd / disable-selection jqueryui-amd / focusable jqueryui-amd / ie jqueryui-amd / keycode jqueryui-amd / plugin jqueryui-amd / position jqueryui-amd / safe-active-element jqueryui-amd / safe-blur jqueryui-amd / scroll-parent jqueryui-amd / tabbable jqueryui-amd / unique-id jqueryui-amd / version jqueryui-amd / widget jqueryui-amd / widgets / draggable jqueryui-amd / widgets / mouse jqueryui-amd / widgets / sortable剔除淘汰表ojL10n ojdnd ojs / internal-deps / dvt / vvtAxis ojs / internal-deps / deps ojs / internal-deps / dvt / DvtDiagram ojs / internal-deps / dvt / DvtGauge ojs / internal-deps / dvt / DvtLegend ojs / internal-deps / dvt / DvtNBox ojs / internal-deps / dvt / DvtOverview ojs / inv / dvt / DvtPanZoomCanvas ojs / internal-deps / dvt / DvtPictoChart ojs / internal-deps / dvt / DvtSubcomponent ojs / internal-deps / dvt / DvtTagCloud ojs / internal-deps / dvt / DvtThematicMap ojs / Time-Axis /整数rnal-deps / dvt / DvtTimeComponent ojs / internal-deps / dvt / DvtTimeline ojs / internal-deps / dvt / DvtToolkit ojs / internal-deps / dvt / DvtTreeView ojs / ojaccordion ojs / ojanimation ojs / ojarraydatajs数据源/ ojbutton ojs / ojchart ojs / ojcheckboxset ojs / ojcollapsible ojs / ojcollectiondatagriddatasource ojs / ojcollectionpagingdatasource ojs / ojcollectiontabledatasource ojs / ojcollectiontreedatasource ojs / ojcomponentcore ojs / ojcomponents ojs / ojconveyorcomc utils ojs / ojdatagrid ojs / ojdatagrid-model ojs / ojdataprovider ojs / ojdataprovideradapter ojs / ojdatasource-common ojs / ojdatetimepicker ojs / ojdefer ojs / ojdiagram ojs / ojdialog ojs / ojdomscroller ojs / ojoable / oj / ojdabletscript / ojflattenedtreedatagriddatasource ojs / ojflattenedtreetabledatasource ojs / ojgauge ojs / ojindexer ojs / ojinputnumber ojs / ojinputtext ojs / ojjquery-hammer o js / ojjsontreedatasource ojs / ojkeyset ojs / ojknockout ojs / ojknockout-model ojs / ojknockout-validation ojs / ojkoshared ojs / ojlabel ojs / ojlegend ojs / ojlistdataproviderview ojs / ojlistview ojs / ojosonojs / ojoson / js / ojmoduleanimations ojs / ojnavigationlist ojs / ojnbox ojs / ojoffcanvas ojs / ojoptgroup ojs / ojoption ojs / ojpagingcontrol ojs / ojpagingcontrol-model ojs / ojpagingdatagriddatasource ojs / ojpagingtabledatasource ojs / ojpictochart ojs / ojpopupojs / ojradiocheckbox ojs / ojradioset ojs / ojrouter ojs / ojrowexpander ojs / ojselectcombobox ojs / ojslider ojs / ojsunburst ojs / ojswipetoreveal ojs / ojswitch ojs / ojtable ojs / ojtable-model ojs / ojtabs ojs / ojtags ojs / ojtags基本ojs / ojtimeline ojs / ojtoolbar ojs / ojtouchproxy ojs / ojtrain ojs / ojtree ojs / ojtree-model ojs / ojtreemap ojs / ojvalidation ojs / ojvalidation-base ojs / ojvalidation-datetime ojs / ojvalidation-numb er ojtranslations / nls / localeElements ojtranslations / nls / ojtranslations承诺信号文本“ .split(”“)}; window.getUifwkBundles = function(){返回window.isDevMode?[]:“ uifwk / js / util / ajax-util uifwk / js / util / df-util uifwk / js / util / logging-util uifwk / js / sdk /日志记录功能使用util uifwk / js / util / message-util uifwk / js / util / mobile-util uifwk / js / util / preference-util uifwk / js / util / screenshot-util uifwk / js / util / typeahead -搜索uifwk / js / util / usertenant-util uifwk / js / util / zdt-util uifwk / js / util / uifwk-preload-util uifwk / js / sdk / context-util uifwk / js / sdk / menu-util uifwk / js / widgets / aboutbox / js / aboutbox uifwk / js / widgets / brandingbar / js / brandingbar uifwk / js / widgets / datetime-picker / js / datetime-picker uifwk / js / widgets / navlinks / js / navigation-links uifwk / js / widgets / timeFilter / js / timeFilter uifwk / js / widgets / widgetselector / js / widget-selector uifwk / js / widgets / tooltip / tooltip uifwk / js / sdk / widget-selector-util文本!uifwk / js / widgets /aboutbox/html/aboutbox.html文字!uifwk / js / widgets / navlinks / html / navigation-links.html文字!uifwk / js / widgets / brandingbar / html / brandingbar.html文字!uifwk / js / widgets / timeFilter / html /时间Filter.html文本!uifwk / js / widgets / datetime-picker / html / datetime-picker.html文本!uifwk / js / widgets / widgetselector / html / widget-selector.html“ .split(”“)}; //#sourceMappingURL = jetLoader.map

这是这里的文件内容,我只想用return语句替换 window.getJetPaths 整个定义。 由于无法替换“ /,{,}”

而出现错误
Below is my script:

#!/bin/bash
filePath='D:/emsaasui/uifwk/libs/4.2.0-41239/js/jetLoader.js'

line=$(awk '/getJetPaths/{print NR}' $filePath)
str=$(tail -n +$line $filePath)
#echo $str
tempStr=""
count=0
for (( i=0 ; i < ${#str} ; i++ )) {
    arr[$i]=${str:i:1}
    #printf "%s\n" "${arr[@]}"
        if [[ ${arr[$i]} = '{' ]]
        then
        count=$((count+1))
        echo $count
    fi
        if [[ $count -eq "1" || $count -eq "2" ]]
        then
        tempStr=${tempStr}${arr[$i]}

        fi
        if [[ ${arr[$i]} = '}' ]]
        then
        count=$((count-1))
       if [[ $count = 0 ]]
        then
        break
        fi
   fi
   }
   echo $tempStr
sed 's/\\$tempStr{\([^}]*\)}/\1 %/g'

谢谢。

1 个答案:

答案 0 :(得分:1)

最简单的情况-还是全都放在一行上。只是做一个字面替换。 假设文件名为x-

sed 's/window.getJetPaths=function.*return b};/window.getJetPaths=function(b){return b};/' x > y

观看元字符。 Sed给这些词赋予特殊含义,除非经过仔细鉴定或包含在广泛匹配中,否则它们将不匹配。