簡體   English   中英

shell 腳本在重復數據文件中查找特定模式。 並在匹配模式之前添加新的空行

[英]shell script to Find a particular Pattern in repetitive data a file . and add new blank line before matched pattern

我需要在文件中找到一個特定的模式,如果找到模式,然后添加一個空行並再次搜索相同的模式。

我的文件.txt

Apple_123_fruit   
 fruit
 1
 Apple_456_fruit   
 fruit_2
 2

所以我想搜索以apple開頭的字符串,然后是*,如果找到該模式,則將以下3行添加到一行中,然后添加一個空行並再次對第二條記錄重復相同的操作。

output 應該喜歡:

Apple_123_fruit  fruit 1

Apple_456_fruit fruit_2 2

任何人都可以在這里幫忙。

該算法應該有效:

  • 將所有內容文件轉換為一個字符串
  • 使用正則表達式搜索單個數字
  • 如果匹配,打印斷線

我將使用確切的命令進行更新

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM