I am looking for every occurence of a search term, e.g. ddd
, in a file and output the surroundings, like this:
File.txt
aaa bbb ccc ddd eee fff
ttt uuu iii eee ddd
ddd
ggg jjj kkk ddd lll
output
ccc ddd eee
eee ddd
ddd
kkk ddd lll
As a starting point, I am using this piece of code
#!/usr/bin/perl -w
while(<>) {
while (/ddd(\d{1,3}))/g) {
print "$1\n"
}
}