Python Forum
Need print out lines before and after the match
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need print out lines before and after the match
#3
I do not know what that means "Why don't you just join lines[index-4] to lines[index+4]?"
Line ("".join(lines[max(0,index-4):index])) works fine.
It is 4 lines after a "match' Im having problem with.

I tried adding one more print statement but it does not print anything

            print("".join(lines[max(0,index-4):index]))  # print 4 lines preceeding it
            print("".join(lines[max(0,index+4):index]))  # print 4 lines after it
thank you.
Reply


Messages In This Thread
RE: Need print out lines before and after the match - by tester_V - Aug-10-2020, 03:29 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Print the next 3 lines knob 3 1,226 May-22-2024, 12:26 PM
Last Post: andraee
  failing to print not matched lines from second file tester_V 14 9,211 Apr-05-2022, 11:56 AM
Last Post: codinglearner
  If match not found print last line tester_V 2 3,715 Apr-26-2021, 05:18 AM
Last Post: tester_V
  why print('\n') produced 2 new lines instead of 1 - Located inside a FOR loop JulyFire 2 3,661 Jan-10-2021, 01:50 AM
Last Post: JulyFire
  Iterate 2 large text files across lines and replace lines in second file medatib531 13 9,314 Aug-10-2020, 11:01 PM
Last Post: medatib531
  Look for match in two files and print out in the first file Batistuta 0 2,093 Mar-03-2020, 02:27 PM
Last Post: Batistuta
  print python json dump onto multiple lines lhailey 2 24,241 Mar-02-2020, 12:47 PM
Last Post: vishalhule
  Read serial BR=9600 . print me 2 lines? korenron 1 3,010 Dec-31-2019, 06:39 PM
Last Post: DeaD_EyE
  using vars from one file to match lines in another gt76_noobster 3 3,402 Jan-30-2019, 05:34 PM
Last Post: ichabod801
  Print multiple record lines ntigner 3 4,254 Feb-08-2018, 05:34 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020