- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Another scripting problem
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2002 08:53 PM
10-07-2002 08:53 PM
This could be a simple problem to you but very complex for me :)
I need to write a script that will grep the content of a program which looks something like this.
pm_9769625.log for details
Wed Oct 2 08:44:17 2002 #9769695# Route status has changed to bad: arc-id=1, Me
ssage:administrative route = APM_X25_BRICKFIELD_U2_SPONT1_CONCHECK See APM log c
6xapm_9769625.log for details
Wed Oct 2 09:28:18 2002 #9769695# Route status has changed to ok: arc-id=1, Mes
sage:administrative route = APM_X25_BRICKFIELD_U2_SPONT1_CONCHECK See APM log c6
xapm_9769625.log for details
============================ Currently Bad Routes ==============================
Sun Oct 6 16:46:32 2002 #9769641# Route status has changed to bad: arc-id=1, Me
ssage:administrative route = APM_X25_YONG_PENG_SPONT1_CONCHECK See APM log c6xap
m_9769625.log for details
How can I grep only the lines after the line "============================ Currently Bad Routes ==============================
"?
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2002 09:09 PM
10-07-2002 09:09 PM
Re: Another scripting problem
sed '/----,$/p' your_file_name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2002 09:17 PM
10-07-2002 09:17 PM
Re: Another scripting problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2002 09:20 PM
10-07-2002 09:20 PM
Re: Another scripting problem
In awk it's like this
awk '{line[NR]=$0;
if ( line[NR] ~ /====== Currently Bad Routes ====/ )
border=NR}
END
{for (i=border+1;i<=NR;i++) print line[i]
}
' filename
Short explanation:
you read the whole file:
line[NR]=$0
remember the line number with the searchpattern
if ( line[NR] ~ /====== Currently Bad Routes ====/ )
border=NR}
and only shows the file from this line to the end
for (i=border+1;i<=NR;i++) print line[i]
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2002 09:26 PM
10-07-2002 09:26 PM
Re: Another scripting problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2002 09:28 PM
10-07-2002 09:28 PM
Re: Another scripting problem
As in all unix scripts, there are no doubt a dozen ways to do this, six of which are acceptable, and a couple of which are ideal.
I think I would start by using a combination of 'wc -l' to determine how many lines total are in the file, and keeping that in a variable.
Then, with 'grep -n ...', grep for the '== Currently Bad Routes ==' string, which would give you the line number for that line. You could create a variable that was the difference between that line and the last line, call it, say, DIFF.
Then, I would use 'tail -$DIFF' on the file, and pipe it to 'grep', which would let you search for whatever you want to match, in just the lines following the "Current Bad Routes" string.
Very possibly, this could all be done in one massive command line, but it would be much simpler to do it as several lines in a script.
I have no machine to hack up a workable version just now, so I'll have to leave it at this, aside from suggesting that the use of 'sed', 'awk', or 'ed' can probably make short work of this, but I have not mastered them enough to suggest exactly how. Then there's perl...
Anyway, I hope these ideas are enough to get you started. Hopefully, they are somewhere in the top six, not the bottom six, of the dozen workable suggestions.
Regards, --bmr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2002 09:29 PM
10-07-2002 09:29 PM
Re: Another scripting problem
As in all unix scripts, there are no doubt a dozen ways to do this, six of which are acceptable, and a couple of which are ideal.
I think I would start by using a combination of 'wc -l' to determine how many lines total are in the file, and keeping that in a variable.
Then, with 'grep -n ...', grep for the '== Currently Bad Routes ==' string, which would give you the line number for that line. You could create a variable that was the difference between that line and the last line, call it, say, DIFF.
Then, I would use 'tail -$DIFF' on the file, and pipe it to 'grep', which would let you search for whatever you want to match, in just the lines following the "Current Bad Routes" string.
Very possibly, this could all be done in one massive command line, but it would be much simpler to do it as several lines in a script.
I have no machine to hack up a workable version just now, so I'll have to leave it at this, aside from suggesting that the use of 'sed', 'awk', or 'ed' can probably make short work of this, but I have not mastered them enough to suggest exactly how. Then there's perl...
Anyway, I hope these ideas are enough to get you started. Hopefully, they are somewhere in the top six, not the bottom six, of the dozen workable suggestions.
Regards, --bmr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2002 09:29 PM
10-07-2002 09:29 PM
Re: Another scripting problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2002 09:30 PM
10-07-2002 09:30 PM
Re: Another scripting problem
I got the following error:-
syntax error The source line is 5.
The error context is
END >>>
<<<
awk: Quitting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2002 09:34 PM
10-07-2002 09:34 PM
Re: Another scripting problem
As in all unix scripts, there are no doubt a dozen ways to do this, six of which are acceptable, and a couple of which are ideal.
I think I would start by using a combination of 'wc -l' to determine how many lines total are in the file, and keeping that in a variable.
Then, with 'grep -n ...', grep for the '== Currently Bad Routes ==' string, which would give you the line number for that line. You could create a variable that was the difference between that line and the last line, call it, say, DIFF.
Then, I would use 'tail -$DIFF' on the file, and pipe it to 'grep', which would let you search for whatever you want to match, in just the lines following the "Current Bad Routes" string.
Very possibly, this could all be done in one massive command line, but it would be much simpler to do it as several lines in a script.
I have no machine to hack up a workable version just now, so I'll have to leave it at this, aside from suggesting that the use of 'sed', 'awk', or 'ed' can probably make short work of this, but I have not mastered them enough to suggest exactly how. Then there's perl...
Anyway, I hope these ideas are enough to get you started. Hopefully, they are somewhere in the top six, not the bottom six, of the dozen workable suggestions.
Regards, --bmr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2002 09:39 PM
10-07-2002 09:39 PM
Re: Another scripting problem
Well, between procura and I, we've used up a drive on the HP web site... Sorry about this, I expect we had the same problem of 'submit' hanging (try again, repeat as necessary...)
If an HP person happens by, maybe they can clean this one up a little.
Oh well, what's a 73GB drive among friends?
8^)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2002 09:44 PM
10-07-2002 09:44 PM
Re: Another scripting problem
Aminur, sorry :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2002 09:46 PM
10-07-2002 09:46 PM
Re: Another scripting problem
It doesnt work for me .
Brian,
I agree with your suggestion
For your info the lines are actually output from a troubleshooting script which actually varies with time depends on the errors .
Meant that it is impossible for me to get the number of lines, as it varies.
Still haven't find the right solutions :(
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2002 10:15 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2002 10:34 PM
10-07-2002 10:34 PM
Re: Another scripting problem
Great!!!
It really works this time.
Thanks all, especially for Chris.
You really make my day!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2002 12:11 AM
10-08-2002 12:11 AM
Re: Another scripting problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2002 04:23 AM
10-09-2002 04:23 AM
Re: Another scripting problem
ANOTHER WAY:
START=`grep -E -n "== Currently Bad Routes ==" yourfile | awk -F: '// {print $1}' `
cat yourfile | sed -n "$START,$p" > your_smaller_file.
another way explained:
Let's say the line you want is line 345.
grep -E -n "== Currently Bad Routes ==" yourfile
Returns 345: == Currently Bad Routes ==
The awk -F: '// {print $1}' gives you the first number (345).
sed -n '345,$p' Says to print only from line 345 to the end (aka $) of the file.
But we use double quotes to interpolate the variable. So
sed -n "$START,$p" becomes sed -n "345,$p"
FYI: I had a problem in the past where the size of the file was so big, I exceeded the ability for tail to get all of the information. Or it was a limit through the pipe "|"? I just remembered that large files had some bizare effects.