The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to extract date with time from file prash_b Shell Programming and Scripting 5 06-18-2008 05:30 AM
Extract words before and after a pattern/regexp manthasirisha Shell Programming and Scripting 3 03-21-2008 03:38 AM
extract words with even numbr of letters manish205 Shell Programming and Scripting 3 02-19-2008 03:18 AM
Extract TIME ndoggy020 UNIX for Dummies Questions & Answers 4 05-08-2007 05:06 PM
How to grep for two or more words in a line at the same time? ElCaito Shell Programming and Scripting 2 03-01-2006 07:48 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-30-2008
Registered User
 

Join Date: Apr 2008
Posts: 18
Stumble this Post!
How to extract two words at the same time.

Hi, Can anyone please let me know, how to extract two lines at the same time. In specific,I have a file containing list of devices, such as router1 and switch2 below. I want to get all the lines which has "#" and all the lines which has "down"


router1#sh ip int br
Interface IP-Address OK? Method Status Protocol^M
Vlan1 unassigned YES NVRAM up down ^M
Vlan100 10.71.12.202 YES NVRAM up up ^M
FastEthernet0/1 unassigned YES unset down down ^M
GigabitEthernet0/1 unassigned YES unset up up ^M
GigabitEthernet0/2 unassigned YES unset up up ^M
router1#
router1#exit

switch2#^M
switch2#term length 0^M
switch2#sh ip int br^M
Interface IP-Address OK? Method Status Protocol^M
Vlan1 unassigned YES NVRAM up down ^M
Vlan400 10.71.12.206 YES NVRAM up up ^M
GigabitEthernet0/1 unassigned YES unset up down ^M
GigabitEthernet0/2 unassigned YES unset up up ^M
switch2#^M




I am expected to get the output as:



router1#sh ip int br^M
Vlan1 unassigned YES NVRAM up down ^M
FastEthernet0/1 unassigned YES unset down down ^M
router1#
router1#exit


switch2#^M
switch2#term length 0^M
switch2#sh ip int br^M
Vlan1 unassigned YES NVRAM up down ^M
GigabitEthernet0/1 unassigned YES unset up down ^M
switch2#^M



Regards,A

Last edited by Aejaz; 04-30-2008 at 03:12 AM.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-30-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,953
Stumble this Post!
Code:
egrep '#|down' file
or:

Code:
awk '/#/||/down/' file
Regards
Reply With Quote
  #3 (permalink)  
Old 04-30-2008
Registered User
 

Join Date: Apr 2008
Posts: 18
Stumble this Post!
Franklin, Thanks a Million, It works.
I am getting an unusual character at the end of every line.
^M at the end of every line when i do more.
Reply With Quote
  #4 (permalink)  
Old 04-30-2008
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,572
Stumble this Post!
thats not unusual,

its there in the source feed

Code:
sed 's/^M//g' filename
Reply With Quote
  #5 (permalink)  
Old 04-30-2008
Registered User
 

Join Date: Apr 2008
Posts: 18
Stumble this Post!
^M goes away when I execute the command, but when I say
sed 's/^M//g' filename | more
it appears again.
Reply With Quote
  #6 (permalink)  
Old 04-30-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,953
Stumble this Post!
^M is not just the characters "^" and "M", you must first type Ctr-V then Ctrl-M.

Regards
Reply With Quote
  #7 (permalink)  
Old 04-30-2008
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,572
Stumble this Post!
either you have to redirect the output to some other filename or do an in-place edit with "-i" option

Code:
sed -i 's/^M//g' filename
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0