Shell Scripting Help
I'm new, and I wasn't sure if this was the correct thread to post this in. And if this isn't, I would be very appreciative if it was moved into the correct thread.
I am having a problem figuring out how to tackle this problem. I'm currently trying to go through some of my log files to copy out a night's import into a different file. There would be two keywords that would signify the start and end of the section I would copy out. Or, rather, the "keywords" would be a date on its first appearance into the text file. I couldn't find something on google to help me figure out the correct method of putting this in a shell script. Help? Thank you. |
awk will sure do the job.
|
Okay! But, I'm not entirely sure how to use awk... or, rather, I've read it, but I'm not entirely sure how to use it. May I get some help with that?
|
Lets assume you have a file containing:
Code:
one two three Code:
awk 'BEGIN{x=0}{if ($3=="C") {x=0};if (x) {print};if ($2=="five") {x=1}}' file This will only work assuming the second condition never appears before the first condition, which is what I have understand from your first post. Anyway, its something rough as an example. BEGIN clause will only execute once at the begining of awk. The rest of the code will be executed for every line read from file. |
awk would do it but sed is better suited to the task.
Use Ranges by patterns to define the lines you want to extract and p to print them. |
Member response
Hi,
Welcome to LQ! Quote:
Linux Documentation Project Rute Tutorial & Exposition Linux Command Guide Utimate Linux Newbie Guide LinuxSelfHelp Bash Beginners Guide Bash Reference Manual Advanced Bash-Scripting Guide Linux Home Networking The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links! |
All times are GMT -5. The time now is 12:48 AM. |