need help with a script that involves awk and sed
Hi guys,
I need some assistance in writing a small script.
I have some IRC logs that I need the script to go through and print out the lines in which a URL is written.
I can currently do 'less logfile | grep 'http' > links' to get all the URLs from the particular log.
What I want to do is make the script print out 5 lines before and after the URL is mentioned.
So I'm thinking that I can use sed to number all the lines in the log file, use awk to print out the lines where a URL is mentioned, somehow store each line number into a variable and feed each variable to sed again to print out the 5 preceding and following lines.
from my research:
sed '$!N;s/\n/ /' logfile > logfile1 will number all the lines of the log file. I can then do:
less logfile1 | grep 'http' | awk {print '$1'}
This will print out the lines (numbers) where a URL is mentioned. I also know that I can use "sed -n '45,50p' filename" to print lines numbered 45-50. So, I'm thinking if I can store each number as a variable, I can have the script print the 5 lines before and after that line into a new file.
Can anything like this be done?
|