Apr 26, 2016 #1 smik Technical User Apr 26, 2016 2 AU Hi looking for a single line command to search for line and print line immediately above plus the second line, third line and fourth line above awk '/search_for_string/{x=$0;next}{print x";"$0;}' Thanks in advance Mik
Hi looking for a single line command to search for line and print line immediately above plus the second line, third line and fourth line above awk '/search_for_string/{x=$0;next}{print x";"$0;}' Thanks in advance Mik
Apr 26, 2016 1 #2 feherke Programmer Aug 5, 2002 9,540 RO Hi From your code I deduce that you want each set of matches on one line, separated with semicolon, including the matched line itself. Code: awk '/search_for_string/{for(i=0;i<4;i++)printf"%s;",a[(i+NR)%4];print}{a[NR%4]=$0}' Feherke. feherke.ga Upvote 0 Downvote
Hi From your code I deduce that you want each set of matches on one line, separated with semicolon, including the matched line itself. Code: awk '/search_for_string/{for(i=0;i<4;i++)printf"%s;",a[(i+NR)%4];print}{a[NR%4]=$0}' Feherke. feherke.ga
Apr 28, 2016 Thread starter #3 smik Technical User Apr 26, 2016 2 AU Hi Feheke, Thank you for the one liner much appreciated Upvote 0 Downvote