亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
123下一頁
最近訪問板塊 發(fā)新帖
查看: 4120 | 回復(fù): 20
打印 上一主題 下一主題

[文本處理] 將一對標(biāo)志符之間的多行合并成一行 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2015-05-18 19:55 |只看該作者 |倒序瀏覽
本帖最后由 yelang5460 于 2015-05-18 19:55 編輯

想將下面的文本中<>之間的部分的多行數(shù)據(jù)格式化成這樣的一行行數(shù)據(jù),以方便后期查找替換...
<favorite launcher:packageName="com.android.browser" launcher:className="com.android.browser.BrowserActivity" launcher:screen="3" />

<favorite之前可能有多個空格或者tab ,<favorite然后后面還可能有回車 空格或者換行









<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

         

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<favorites xmlns:launcher="//schemas.android.com/apk/res/com.sec.android.app.launcher">
    <home>
     
       
        <!-- Left screen [1] -->        
       
        <appwidget
        launcher:packageName="com.sec.android.widgetapp.digitalclock"
        launcher:className="com.sec.android.widgetapp.digitalclock.DigitalClockWidgetProvider"
        launcher:screen="1"
        launcher:x="0"
        launcher:y="0"
        launcher:spanX="4"
        launcher:spanY="1" />      
        
            <search
        launcher:screen="1"
        launcher:x="0"
        launcher:y="2" />
                        
        <favorite
        launcher:packageName="com.android.email"
        launcher:className="com.android.email.activity.Welcome"
        launcher:screen="1"
        launcher:x="0"
        launcher:y="3" />
                        
        <favorite
        launcher:packageName="com.sec.android.app.camera"
        launcher:className="com.sec.android.app.camera.Camera"       
        launcher:screen="1"
        launcher:x="1"
        launcher:y="3" />
  
        <favorite
        launcher:packageName="com.sec.android.app.samsungapps"
        launcher:className="com.sec.android.app.samsungapps.Main"
        launcher:screen="1"
        launcher:x="2"
        launcher:y="3" />


        <favorite
        launcher:packageName="com.sec.chaton"
        launcher:className="com.sec.chaton.HomeActivity"
        launcher:screen="1"
        launcher:x="3"
        launcher:y="3" />
                     
       
    </home>
    <!-- Hotseat (We use the screen as the position of the item in the hotseat) -->
    <hotseat>
        <favorite
            launcher:packageName="com.android.contacts"
            launcher:className="com.android.contacts.activities.DialtactsActivity"
            launcher:screen="0" />
        <favorite
            launcher:packageName="com.android.contacts"
            launcher:className="com.android.contacts.activities.PeopleActivity"
            launcher:screen="1" />
        <favorite
            launcher:packageName="com.android.mms"
            launcher:className="com.android.mms.ui.ConversationComposer"
            launcher:screen="2" />
        <favorite
            launcher:packageName="com.android.browser"
            launcher:className="com.android.browser.BrowserActivity"
            launcher:screen="3" />
     </hotseat>
</favorites>

論壇徽章:
9
射手座
日期:2014-07-29 13:05:07雙子座
日期:2015-01-11 17:01:522015年亞洲杯之朝鮮
日期:2015-02-01 16:14:282015亞冠之阿爾艾因
日期:2015-06-04 17:54:40數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2015-08-02 06:20:00數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2015-10-28 06:20:00數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2015-11-26 06:20:0015-16賽季CBA聯(lián)賽之天津
日期:2016-06-20 17:09:2015-16賽季CBA聯(lián)賽之青島
日期:2017-02-26 15:54:19
2 [報告]
發(fā)表于 2015-05-18 20:28 |只看該作者
  1. sed '/<[^>]\+$/{:a;N;/>/!ba;s/\n//g}'
復(fù)制代碼

論壇徽章:
2
數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2015-07-04 22:20:00IT運維版塊每日發(fā)帖之星
日期:2015-11-25 06:20:00
3 [報告]
發(fā)表于 2015-05-18 20:32 |只看該作者
BEGIN {FS="\n" RS="" ORS=""} 類似這樣的分割方法,將每一段看作一個記錄,而將每一段中的每一條字符串看作一個字段

論壇徽章:
2
數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2015-07-04 22:20:00IT運維版塊每日發(fā)帖之星
日期:2015-11-25 06:20:00
4 [報告]
發(fā)表于 2015-05-18 20:59 |只看該作者
可否詳細(xì)解釋一下,尤其{}內(nèi)的語法回復(fù) 2# stupid_lee


   

論壇徽章:
20
卯兔
日期:2015-01-26 22:05:142015亞冠之薩濟拖拉機
日期:2015-09-10 15:15:282015亞冠之阿爾希拉爾
日期:2015-09-25 17:37:53程序設(shè)計版塊每日發(fā)帖之星
日期:2015-10-03 06:20:00程序設(shè)計版塊每日發(fā)帖之星
日期:2015-12-09 06:20:00CU十四周年紀(jì)念徽章
日期:2015-12-17 09:07:15程序設(shè)計版塊每日發(fā)帖之星
日期:2015-12-25 06:20:34程序設(shè)計版塊每日發(fā)帖之星
日期:2015-12-25 06:20:34程序設(shè)計版塊每日發(fā)帖之星
日期:2015-12-25 06:20:342015亞冠之廣州富力
日期:2015-08-27 19:29:56每日論壇發(fā)貼之星
日期:2015-08-26 06:20:002015亞冠之阿爾希拉爾
日期:2015-05-18 17:26:27
5 [報告]
發(fā)表于 2015-05-18 22:21 |只看該作者
回復(fù) 1# yelang5460
  1. sed -nr '/<[^>]+$/{h;:a;n;H;/>/!ba;g;s/(\n)+ */ /gp;d};/^ *$/!p' file
復(fù)制代碼
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- Copyright (C) 2009 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -->
  3. <favorites xmlns:launcher="//schemas.android.com/apk/res/com.sec.android.app.launcher">
  4.     <home>
  5.         <!-- Left screen [1] -->
  6.         <appwidget launcher:packageName="com.sec.android.widgetapp.digitalclock" launcher:className="com.sec.android.widgetapp.digitalclock.DigitalClockWidgetProvider" launcher:screen="1" launcher:x="0" launcher:y="0" launcher:spanX="4" launcher:spanY="1" />
  7.             <search launcher:screen="1" launcher:x="0" launcher:y="2" />
  8.         <favorite launcher:packageName="com.android.email" launcher:className="com.android.email.activity.Welcome" launcher:screen="1" launcher:x="0" launcher:y="3" />
  9.         <favorite launcher:packageName="com.sec.android.app.camera" launcher:className="com.sec.android.app.camera.Camera"         launcher:screen="1" launcher:x="1" launcher:y="3" />
  10.         <favorite launcher:packageName="com.sec.android.app.samsungapps" launcher:className="com.sec.android.app.samsungapps.Main" launcher:screen="1" launcher:x="2" launcher:y="3" />
  11.         <favorite launcher:packageName="com.sec.chaton" launcher:className="com.sec.chaton.HomeActivity" launcher:screen="1" launcher:x="3" launcher:y="3" />
  12.     </home>
  13.     <!-- Hotseat (We use the screen as the position of the item in the hotseat) -->
  14.     <hotseat>
  15.         <favorite launcher:packageName="com.android.contacts" launcher:className="com.android.contacts.activities.DialtactsActivity" launcher:screen="0" />
  16.         <favorite launcher:packageName="com.android.contacts" launcher:className="com.android.contacts.activities.PeopleActivity" launcher:screen="1" />
  17.         <favorite launcher:packageName="com.android.mms" launcher:className="com.android.mms.ui.ConversationComposer" launcher:screen="2" />
  18.         <favorite launcher:packageName="com.android.browser" launcher:className="com.android.browser.BrowserActivity" launcher:screen="3" />
  19.      </hotseat>
  20. </favorites>
復(fù)制代碼

論壇徽章:
20
卯兔
日期:2015-01-26 22:05:142015亞冠之薩濟拖拉機
日期:2015-09-10 15:15:282015亞冠之阿爾希拉爾
日期:2015-09-25 17:37:53程序設(shè)計版塊每日發(fā)帖之星
日期:2015-10-03 06:20:00程序設(shè)計版塊每日發(fā)帖之星
日期:2015-12-09 06:20:00CU十四周年紀(jì)念徽章
日期:2015-12-17 09:07:15程序設(shè)計版塊每日發(fā)帖之星
日期:2015-12-25 06:20:34程序設(shè)計版塊每日發(fā)帖之星
日期:2015-12-25 06:20:34程序設(shè)計版塊每日發(fā)帖之星
日期:2015-12-25 06:20:342015亞冠之廣州富力
日期:2015-08-27 19:29:56每日論壇發(fā)貼之星
日期:2015-08-26 06:20:002015亞冠之阿爾希拉爾
日期:2015-05-18 17:26:27
6 [報告]
發(fā)表于 2015-05-18 22:38 |只看該作者
本帖最后由 songyc_2015 于 2015-05-18 23:31 編輯

回復(fù) 1# yelang5460
  1. awk '/</{p=1}/>/{p=0;s=length(s)?s"# "$0:$0;gsub(/# +/," ",s);print s;s=""}p{s=length(s)?s"# "$0:$0}' file
  2. awk '/</,/>/{s=length(s)?s"# "$0:$0;if($0~/>/){gsub(/# +/," ",s);print s;s=""}}' file
復(fù)制代碼

論壇徽章:
30
申猴
日期:2014-04-10 09:43:532015年亞洲杯紀(jì)念徽章
日期:2015-03-20 14:40:232015亞冠之阿爾納斯?fàn)?日期:2015-06-02 18:59:042015亞冠之阿爾希拉爾
日期:2015-06-30 15:22:572015亞冠之大阪鋼巴
日期:2015-07-20 10:44:332015亞冠之阿爾納斯?fàn)?日期:2015-10-28 14:57:5215-16賽季CBA聯(lián)賽之新疆
日期:2015-12-25 10:18:45黑曼巴
日期:2016-06-26 21:39:5315-16賽季CBA聯(lián)賽之山西
日期:2016-07-25 21:54:2715-16賽季CBA聯(lián)賽之北京
日期:2016-10-27 12:07:2315-16賽季CBA聯(lián)賽之八一
日期:2017-07-07 16:39:0915-16賽季CBA聯(lián)賽之吉林
日期:2017-09-04 12:14:43
7 [報告]
發(fā)表于 2015-05-19 00:12 |只看該作者
  1. awk '/<.*>/{print $0}/<[^>]+$/{p=1;t=$0;next}p&&!/^$/{t=t" "gensub(/^[ ]+/,"","G",$0)}/\/>|^ -->/{print t;t=""}' file
復(fù)制代碼
回復(fù) 1# yelang5460


   

論壇徽章:
0
8 [報告]
發(fā)表于 2015-05-19 09:57 |只看該作者
感謝樓上各位大神

sed的語法還是比較好理解的

awk簡直沒法說,看了幾篇基礎(chǔ)文章,來理解這個簡直一頭霧水.....

論壇里的對于awk的高級用法的講解 貌似相關(guān)文章不多啊 哪位大神翻譯一點造福一下大家么......

論壇徽章:
0
9 [報告]
發(fā)表于 2015-05-19 10:16 |只看該作者
回復(fù) 2# stupid_lee

感謝,這行代碼基本實現(xiàn)了我的要求

只是結(jié)果沒有替換多個空格為一個空格  然后各行之間會有一個空行

sed完全可以做到,強....

論壇徽章:
0
10 [報告]
發(fā)表于 2015-05-19 10:19 |只看該作者
回復(fù) 5# songyc_2015



只是我這邊跑出來的結(jié)果出現(xiàn)一個問題

有些行之間出現(xiàn)了一行到兩行的空行

可能是回車符沒替換掉


這行sed代碼還是很贊的  .....
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP