Wednesday, May 15, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 1934  / 3 Years ago, thu, october 21, 2021, 2:57:13

Just curious if there's a way I can show the output between two markers?



I was trying grep -r "<cron_expr>.*</run>" * but it doesn't seem to be returning as
expected. Which is to say its not showing newline breaks?



So I guess the the real question is how can i find out what between two markers
regardless of newline BS. I can't install on this system so no pcregrep =(



Maybe AWK?



(P.s. someone should make an AWK tag)



<crontab>
<jobs>
<enterprise_reward_balance_warning_notification>
<schedule><cron_expr>1 * * * *</cron_expr></schedule>
<run><model>enterprise_reward/observer::scheduledBalanceExpireNotification</model></run>
</enterprise_reward_balance_warning_notification>
<enterprise_reward_expire_points>
<schedule><cron_expr>1 * * * *</cron_expr></schedule>
<run><model>enterprise_reward/observer::scheduledPointsExpiration</model></run>
</enterprise_reward_expire_points>
</jobs>
</crontab>


I just want to show whats on the <schedule> and <run> line(s if more than one, like above) anytime I see and what file they're in.


More From » search

 Answers
4

AWK script



AWK is probably the answer using the /start/,/stop/ pattern like this:



/<schedule>/,/</schedule>/ {
print;
}
/<run>/,/</run>/ {
print;
}


This will print everything in the schedule and run tags (including the tags) and will preserve new lines. Adapt it to print what you need. To run it:



cat myfile.txt | awk -f script.awk


XSLT style sheet



Here's an XSLT version that should do something very similar. Run it using xsltproc, which should be installed by default.



<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="schedule">
<xsl:value-of select="." />
</xsl:template>

<xsl:template match="run">
<xsl:value-of select="." />
</xsl:template>

</xsl:stylesheet>

[#38743] Saturday, October 23, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
diket

Total Points: 167
Total Questions: 124
Total Answers: 109

Location: Somalia
Member since Wed, Mar 15, 2023
1 Year ago
;