Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-04-2012
Registered User
 
Join Date: Jul 2005
Posts: 94
Thanks: 11
Thanked 0 Times in 0 Posts
Filter a particular string

Hi,
I have a long log file. Out of which I want to filter particular occurrences where APC=4-033-0.

Please help how it can be done.

Input :

Code:
+++ ELEMENT 12-05-27 23:15:06 CC 3482 #040185 >
 REPT APB TPE=C7NTL   SM=22  OPC=4-003-7   APC=4-033-4  inaccessible
 END OF REPORT #040185 ++-

+++ ELEMENT 12-05-27 23:15:56 CC 3482 #040187 >
 REPT APB TPE=C7NTL   SM=22  OPC=4-003-7   APC=4-033-0  inaccessible
 END OF REPORT #040187 ++-

+++ ELEMENT 12-05-27 23:16:26 CC 3482 #040188 >
 REPT APB TPE=C7NTL   SM=22  OPC=4-003-7   APC=4-033-6  inaccessible
 END OF REPORT #040188 ++-

Output :

Code:
OPC=4-003-7   APC=4-033-0  inaccessible 12-05-27 23:15:56

Thanks in advance.

Last edited by Scrutinizer; 06-04-2012 at 02:52 AM.. Reason: code tags
Sponsored Links
    #2  
Old 06-04-2012
jayan_jay's Avatar
Forum Advisor
 
Join Date: Jul 2008
Posts: 831
Thanks: 9
Thanked 185 Times in 176 Posts
Based on the input given ..

Code:
$ nawk '/APC=4-033-0/{print $5,$6,$7,x};{x=$3" "$4}' infile
OPC=4-003-7 APC=4-033-0 inaccessible 12-05-27 23:15:56

Sponsored Links
    #3  
Old 06-04-2012
Registered User
 
Join Date: Jul 2005
Posts: 94
Thanks: 11
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by jayan_jay View Post
Based on the input given ..

Code:
$ nawk '/APC=4-033-0/{print $5,$6,$7,x};{x=$3" "$4}' infile
OPC=4-003-7 APC=4-033-0 inaccessible 12-05-27 23:15:56

Thanks!!! It works Fine..But getting blank lines in between output. How to suppress them.
    #4  
Old 06-04-2012
balajesuri's Avatar
#! /bin/bash
 
Join Date: Apr 2009
Location: India
Posts: 1,566
Thanks: 14
Thanked 440 Times in 425 Posts
Pipe output to

Code:
| sed '/^ *$/d'

Sponsored Links
    #5  
Old 06-04-2012
jayan_jay's Avatar
Forum Advisor
 
Join Date: Jul 2008
Posts: 831
Thanks: 9
Thanked 185 Times in 176 Posts
Or pipe output to | grep '.'
The Following User Says Thank You to jayan_jay For This Useful Post:
vanand420 (06-04-2012)
Sponsored Links
    #6  
Old 06-04-2012
Scrutinizer's Avatar
Moderator
 
Join Date: Nov 2008
Location: Amsterdam
Posts: 7,350
Thanks: 144
Thanked 1,756 Times in 1,593 Posts
Optimal method:

Code:
| awk NF

--

Quote:
Originally Posted by vanand420 View Post
Thanks!!! It works Fine..But getting blank lines in between output. How to suppress them.
Then probably your input file differs from the posted sample you posted. Can you show us in what way?

Last edited by Scrutinizer; 06-04-2012 at 05:34 AM..
The Following User Says Thank You to Scrutinizer For This Useful Post:
vanand420 (06-04-2012)
Sponsored Links
    #7  
Old 06-04-2012
Registered User
 
Join Date: Jul 2005
Posts: 94
Thanks: 11
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Scrutinizer View Post
Optimal method:

Code:
| awk NF

--


Then probably your input file differs from the posted sample you posted. Can you show us in what way?
Thanks..executing the above code "| awk NF" resolved the case.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to filter Naga06 Shell Programming and Scripting 6 07-18-2011 03:20 AM
AWK filter ultimatix Shell Programming and Scripting 8 11-19-2010 01:30 AM
Sed filter words from string amicon007 Shell Programming and Scripting 7 09-13-2010 09:41 AM
filter the string from a file ?? varungupta Shell Programming and Scripting 11 09-17-2007 10:11 PM
Filter using awk arun_st UNIX for Dummies Questions & Answers 3 03-21-2007 08:20 AM



All times are GMT -4. The time now is 10:10 AM.