LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-24-2011, 03:28 PM   #1
krist_m
LQ Newbie
 
Registered: Jan 2011
Posts: 3

Rep: Reputation: 0
using grep for formatting.


Hi,

I have a raw-output.log file as follows:

spawn ssh xxxxxxxx@1.1.1.1
1.1.1.1
=============

*******************************************************************
* This is test *
* *
* Contact IT *
* *
*******************************************************************

Router-101#sh run | i _email_to
event manager environment _email_to noc-group-101@yyy.com
Router-101#exit
Connection to 1.1.1.1 closed by remote host.
Connection to 1.1.1.1 closed.
spawn ssh xxxxxxxx@2.2.2.2
2.2.2.2
=============

*******************************************************************
* This is test *
* *
* Contact IT *
* *
*******************************************************************

Router-202#sh run | i _email_to
event manager environment _email_to noc-group-202@yyy.com
Router-202#exit
Connection to 2.2.2.2 closed by remote host.
Connection to 2.2.2.2 closed.

I need the exact following output:

1.1.1.1
=============
event manager environment _email_to noc-group-101@yyy.com

2.2.2.2
=============
event manager environment _email_to noc-group-202@yyy.com

How do i get this using grep or other methods. Any help will be appreciate.

Thank you.
KM
 
Old 01-24-2011, 04:59 PM   #2
mad4linux
Member
 
Registered: Aug 2003
Distribution: Debian Testing / kubuntu
Posts: 86

Rep: Reputation: 21
You could use this sed line:

Code:
sed -n -e /^[0-9].[0-9].[0-9].[0-9]/,/===/p -e /event/p yourfile.txt
This would give you the following output:
Code:
1.1.1.1
=============
event manager environment _email_to noc-group-101@yyy.com
2.2.2.2
=============
event manager environment _email_to noc-group-202@yyy.com
You can redirect this to a file using > like this
Code:
sed -n -e /^[0-9].[0-9].[0-9].[0-9]/,/===/p -e /event/p yourfile.txt > newfile.txt
 
Old 01-24-2011, 05:04 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Hi, something like this?

Code:
 awk 'BEGIN{FS="\n";RS="closed.\n"} {print $2;print $3;for (i=3;i<=NF;i++){if($i~/event manager/){print $i}};print ""}'  ~/tmp4/routers.
1.1.1.1
=============
event manager environment _email_to noc-group-101@yyy.com

2.2.2.2
=============
event manager environment _email_to noc-group-202@yyy.com

Cheers,
Tink


P.S.: Too slow :} ... and the sed one is prettier.

Last edited by Tinkster; 01-24-2011 at 05:21 PM. Reason: italics
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Grep -p for Linux, Trying to grep a paragraph. ohijames Linux - Newbie 5 07-22-2010 03:09 PM
Trying to understand pipes - Can't pipe output from tail -f to grep then grep again lostjohnny Linux - Newbie 15 03-12-2009 11:31 PM
how to grep multiple filters with grep LinuxLover Linux - Enterprise 1 10-18-2007 08:12 AM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 12:36 PM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 12:38 PM


All times are GMT -5. The time now is 10:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration