2014-07-01 41 views
0

我正在尋找一個sed腳本,將改變如何使用sed刪除空白的未加引號的行?

;; DONE Badge 
;; :PROPERTIES: 
;; :ID:  D0C151F1-384E-4995-B091-1EC1FE265572 
;; :END: 
;; [[http://api.stackexchange.com/docs/types/badge][Official documentation]] 

;; [[file:~/lunch/github/vermiculus/stack-api/stack-api.org::*Badge][Badge:1]] 

(defstruct stack-api/badge 
    "This type represents a badge on a Stack Exchange `stack-api/site'. 

Some badges, like Autobiographer, are held in common across all 
Stack Exchange sites. Others, like most tag badges, vary on a 
site by site basis. 

Remember that ids are never guaranteed to be the same between 
sites, even if a badge exists on both sites." 

    (award-count nil :type integer) 
    (badge-id nil :type integer) ; refers to a badge 
    (badge-type nil :type (memq 'named 
           'tag-based)) 
    (description nil :type string) ; unchanged in unsafe filters 
    (link  nil :type string) ; unchanged in unsafe filters 
    (name  nil :type string) 
    (rank  nil :type (memq 'gold 
           'silver 
           'bronze) 

    (user  nil :type shallow-user)) 

;; Badge:1 ends here 

;; DONE Badge 
;; :PROPERTIES: 
;; :ID:  D0C151F1-384E-4995-B091-1EC1FE265572 
;; :END: 
;; [[http://api.stackexchange.com/docs/types/badge][Official documentation]] 
;; [[file:~/lunch/github/vermiculus/stack-api/stack-api.org::*Badge][Badge:1]] 
(defstruct stack-api/badge 
    "This type represents a badge on a Stack Exchange `stack-api/site'. 

Some badges, like Autobiographer, are held in common across all 
Stack Exchange sites. Others, like most tag badges, vary on a 
site by site basis. 

Remember that ids are never guaranteed to be the same between 
sites, even if a badge exists on both sites." 
    (award-count nil :type integer) 
    (badge-id nil :type integer) ; refers to a badge 
    (badge-type nil :type (memq 'named 
           'tag-based)) 
    (description nil :type string) ; unchanged in unsafe filters 
    (link  nil :type string) ; unchanged in unsafe filters 
    (name  nil :type string) 
    (rank  nil :type (memq 'gold 
           'silver 
           'bronze) 
    (user  nil :type shallow-user)) 
;; Badge:1 ends here 

積分爲在同去消除所有的評論,但我可以用一個管道。我主要不知道如何測試掃描儀是否在一個字符串內。

回答

1

目前還不清楚您是否可以在一行中獲得兩個雙引號。假設沒有,那麼:

sed -e '/"/,/"/{p;d;}' -e '/^ *$/d' 

第一表達對含有雙引號線之間相匹配時,打印每條線和刪除它,然後讀取下一(跳過第二個表達式)。第二個表達式刪除空白行。

如果你在一行上獲得雙引號,那麼你需要:

sed -e '/".*"/{p;d;}' -e '/"/,/"/{p;d;}' -e '/^ *$/d'