代码之家  ›  专栏  ›  技术社区  ›  batman

如何用特定模式grep特定行及其子网行?

  •  0
  • batman  · 技术社区  · 2 年前

    >ab:xy_a0by98-2 \Movie= top gun \actor= Tom \Genere=Action \Length=234 \Credits=30 \pe=1 \summry=(Tom|action|234)
    Top Gun is a 1986 American action drama film directed by Tony Scott, and produced by Don Simpson and Jerry Bruckheimer
    
    >ab:xy_b0ha81-5 \Movie= Thor \actor= chris hemsworth \Genere=Action \Length=321 \Credits=20 \pe=0 \summry=(chris|Action|321)
    Thor embarks on a journey unlike anything he's ever faced a quest for inner peace
    
    >ab:xy_c0ma65-1 \Movie= Batman \actor= Bale \Genere=Action \Length=251 \Credits=30 \pe=1 \summry=(Bale|Action|251)
    From American Psycho to Batman Begins to Vice, Christian Bale is a bonafide A-list star
    But he missed out on plenty of huge roles along the way.
    
    >ab:xy_d0fc78-2 \Movie= Joker \actor= Phoenix \Genere=thriller \Length=341 \Credits=35 \pe=2 \summry=(phoenix|thriller|341)
    Joker is a 2019 American psychological thriller film directed and produced by Todd Phillips
    who co-wrote the screenplay with Scott Silver
    
    >ab:xy_e0ra81-2 \Movie= Superman \actor= henry cavill \Genere=Action \Length=254 \Credits=28 \pe=1 \summry=(cavill|action|254)
    Henry William Dalgliesh Cavill is a British actor
    He is known for his portrayal of Charles Brandon in Showtime's The Tudors
    

    > )其中包含pe=1,每个实体以 > Symbol如下:

    >ab:xy_a0by98-2 \Movie= top gun \actor= Tom \Genere=Action \Length=234 \Credits=30 \pe=1 \summry=(Tom|action|234)
    Top Gun is a 1986 American action drama film directed by Tony Scott, and produced by Don Simpson and Jerry Bruckheimer
    
    >ab:xy_c0ma65-1 \Movie= Batman \actor= Bale \Genere=Action \Length=251 \Credits=30 \pe=1 \summry=(Bale|Action|251)
    From American Psycho to Batman Begins to Vice, Christian Bale is a bonafide A-list star
    But he missed out on plenty of huge roles along the way.
    
    >ab:xy_e0ra81-2 \Movie= Superman \actor= henry cavill \Genere=Action \Length=254 \Credits=28 \pe=1 \summry=(cavill|action|254)
    Henry William Dalgliesh Cavill is a British actor
    He is known for his portrayal of Charles Brandon in Showtime's The Tudors
    

    grep 'pe=1' input.txt 。但它只提取每个记录的第一行。我需要下一行的条目 > 象征

    1 回复  |  直到 2 年前
        1
  •  1
  •   RavinderSingh13 Nikita Bakshi    2 年前

    有了展示的样品,请尝试以下内容 awk > 并且还包含pe=1,然后打印该行。

    tr -d '\r' < Input_file > tmp && mv tmp Input_file
    

    awk -v RS= '/^>.*\\pe=1/' Input_file