- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- parts of the output?
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
11-13-2005 11:59 AM
11-13-2005 11:59 AM
Hi,
line one
line two
line three
line four
I'd like to get "line one" and "line four" only from a log. I don't want to get the lines between them?
10 points for the best answer!
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2005 12:14 PM
11-13-2005 12:14 PM
Re: parts of the output?
sed '1,4!d' LOGFILE | sed '2,3d'
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2005 12:17 PM
11-13-2005 12:17 PM
Re: parts of the output?
> CMD: /dir/example_script 2>&1 /dev/null
> whatever 6827 c Tue Nov 1 10:05:00 EST 2005
< whatever 6827 c Tue Nov 1 10:05:00 EST 2005
< whatever 6821 c Tue Nov 1 10:05:00 EST 2005
< whatever 6823 c Tue Nov 1 10:05:01 EST 2005 rc=126
I'd like to get the "rc=x" and the "CMD" (which is the script that caused the return code)lines. I don't want to get the PID lines between them?
10 points for the best answer!
- Tags:
- cron
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2005 01:54 PM
11-13-2005 01:54 PM
Re: parts of the output?
Welcome to the HPUX forum.
Very few readers here are able to deleted question, and even fewer are in the habit of deleting questions here, no matter how poorly formulated or documented or how poorly the writer indentifies him or herself.
Maybe, just maybe, something went wrong during the 'submit'?
Please help us understand how the script is supposed to recognize the identified lines.
Like whether the word 'four' anywhere on the line is fine, or must is be preceded by line and start the the begin of the line.
Please indicate your preferred tool, if you have one.
This very simple problem can be solve with jsut about all tools: sed, grep, awk, perl, shell scripts.
With grep and the original question:
grep -e "line one|line four" your-file
With awk and your clarification data:
awk '/CMD/;/rc=/' your-file
( if you see CMD then do... the default which is print,
ditto for rc= )
with perl:
perl -ne 'print if /CMD|rc=' your-file
( -n = loop through input but do not print by default
-e = here comes the perl text )
with sed:
sed -n -e "/rc/p" -e"/CMD/p" x
(-n = do not print pattern space be default.
-e = expression
/xyz/ = look for pattern xyz
p = print line on match)
Hope this help some,
Hein.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2005 02:18 PM
11-13-2005 02:18 PM
Re: parts of the output?
Ooops,
I now see in the 'problem' topic
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=971071
that a question with a poorly choosen subject may have been deleted. I would have replied differently, had I seen that before. Oh well, the perills of 'real time' questions and answers.
Regards,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2005 04:12 PM
11-13-2005 04:12 PM
Re: parts of the output?
Here is the output from the awk:
CMD: whatever1.sh 2> /dev/null
< oracle 1003 c Sun Nov 13 19:35:01 EST 2005 rc=126
> CMD: script1.sh > /dev/null 2>&1
> CMD: script2.sh > /dev/null 2>&1
> CMD: script3.sh > /dev/null 2>&1
> CMD: script4.sh > /dev/null 2>&1
> CMD: whatever2.sh 2> /dev/null
< oracle 2003 c Sun Nov 13 19:35:01 EST 2005 rc=126
> CMD: whatever3.sh 2> /dev/null
< oracle 3003 c Sun Nov 13 19:35:01 EST 2005 rc=126
Your solution seemed to grep for all patterns that start with CMD?
Whatever1,whatever2 and whatever3 are correct outputs that I'd like to see but the script1.sh to script4 are unwanted to be seen in the output? since they don't have rc associated with them.
Hope this is more clear.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2005 04:33 PM
11-13-2005 04:33 PM
Solution# grep -E '> CMD|rc=' logfile | awk '{ if ($0~"CMD") { ln1=$0;getline;if($0~"rc="){print ln1"\n"$0;}}}'
# cat logfile
> CMD: whatever1.sh 2> /dev/null
< oracle 1003 c Sun Nov 13 19:35:01 EST 2005 rc=126
> CMD: script1.sh > /dev/null 2>&1
> CMD: script2.sh > /dev/null 2>&1
> CMD: script3.sh > /dev/null:2>&1
> CMD: script4.sh > /dev/null 2>&1
> CMD: whatever2.sh 2> /dev/null
< oracle 2003 c Sun Nov 13 19:35:01 EST 2005 rc=126
> CMD: whatever3.sh 2> /dev/null
< oracle 3003 c Sun Nov 13 19:35:01 EST 2005 rc=126
# grep -E '> CMD|rc=' logfile | awk '{ if ($0~"CMD") { ln1=$0;getline;if($0~"rc="){print ln1"\n"$0;}}}'
> CMD: whatever1.sh 2> /dev/null
< oracle 1003 c Sun Nov 13 19:35:01 EST 2005 rc=126
> CMD: whatever2.sh 2> /dev/null
< oracle 2003 c Sun Nov 13 19:35:01 EST 2005 rc=126
> CMD: whatever3.sh 2> /dev/null
< oracle 3003 c Sun Nov 13 19:35:01 EST 2005 rc=126
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2005 04:54 PM
11-13-2005 04:54 PM
Re: parts of the output?
10 points for you sir!
Just a quick note:
grep -E '> CMD|rc=' logfile
I removed the ">" so the line looks like this:
grep -E 'CMD|rc=' logfile
it worked like a charm!
Thanks again
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2005 04:58 PM
11-13-2005 04:58 PM