I want to delete 1 line above the paatern and 3 line below the pattern and the pattern line itself, on the whole 5 lines. If there are three patterns what to do and the final text file to be captured in a new file.
Please provide input details so somebody can help you out...
try this..(replace pattern with your pattern)
awk '{if ($0 !~ /pattern/){s=$0;getline;if($0 ~ /pattern/){getline;getline;getline}else{print s"\n"$0}}}' file
fkfkdlfjkdlf
fdfdfdf
12345
lkkklkhj
eyoieue
fjdlkfjdlkjflk
876543
ieiereirei
fkfjdklfjd
fdfdkjdf
euieuie
9807654
fkdfjdkfj
fkdfjkf
uiouoiuiu
fdjkdfjdlkjkld
fdkfjdklfjdlk
fdjfkldjlkf
fdjkfkl
fdkfdkfkd
If a txt file contains above lines, in which I want to delte all the number pattern lines
(aboe and below on the whole 5 lines) and the ultimate file should contain the last unpatterned five lines
Try this..(it removes blank lines)
awk '{if ($0 !~ /^[0-9][0-9][0-9]/){if(s){print s;s=$0}else{s=$0}}else{getline;getline;getline}}END{if($0 ~ s){print s}}' file