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 !!

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-20-2013
Registered User
 
Join Date: Jan 2013
Location: Bangalore
Posts: 6
Thanks: 4
Thanked 0 Times in 0 Posts
RedHat Help me to filter a file

I want to view a file ignoring mutilple comment line (/*....*/). Please help me on this.

Advance thanks.
Sponsored Links
    #2  
Old 01-20-2013
Scott's Avatar
Scott Scott is offline Forum Staff  
Administrator
 
Join Date: Jun 2009
Location: Zürich
Posts: 7,166
Thanks: 229
Thanked 808 Times in 698 Posts
In what language, and why have you posted in the Red Hat forum?
Sponsored Links
    #3  
Old 01-20-2013
Registered User
 
Join Date: Jan 2013
Location: Bangalore
Posts: 6
Thanks: 4
Thanked 0 Times in 0 Posts
Actually I want to see configuration file in Linux and I want to view the content which is not commented.
I have tried below command line, but its omitting only the /* */ character not the block which is occupy by /*..*/
Ex:

Code:
cat named.conf | egrep -v "^[[:blank:]]*($|#|//|/\*| \*|\*/)"

Please help me on this.. Thank you.

Last edited by Scott; 01-20-2013 at 06:45 AM.. Reason: Code tags, please...
    #4  
Old 01-20-2013
elixir_sinari's Avatar
Gotham Knight
 
Join Date: Mar 2012
Location: India
Posts: 1,396
Thanks: 92
Thanked 490 Times in 468 Posts
Try:

Code:
perl -p0e 's:/\*.*?\*/::sg' named.conf

The Following User Says Thank You to elixir_sinari For This Useful Post:
Pradipta Kumar (01-21-2013)
Sponsored Links
    #5  
Old 01-20-2013
Yoda's Avatar
Jedi Master
 
Join Date: Jan 2012
Location: Galactic Empire
Posts: 2,516
Thanks: 167
Thanked 818 Times in 787 Posts

Code:
awk 'BEGIN {f=0;}{for(i=1;i<=NF;i++){ if($i=="/*") f=1; if($i=="*/") f=0;
 if(f==0&&!($i=="/*"||$i=="*/")) {
 $i=(i==NF)?$i RS:$i" "; printf "%s", $i ;
 }}
}' named.conf

The Following User Says Thank You to Yoda For This Useful Post:
Pradipta Kumar (01-21-2013)
Sponsored Links
    #6  
Old 01-21-2013
Registered User
 
Join Date: Jan 2013
Location: Bangalore
Posts: 6
Thanks: 4
Thanked 0 Times in 0 Posts
RedHat

Thank you All,,

Both command are working...

Thank you very much
Sponsored Links
Reply

Tags
red hat, unix

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 out data file...? nex_asp Shell Programming and Scripting 5 12-09-2012 04:36 AM
Filter a .kml file (xml) with data set from text file pcoj33 Shell Programming and Scripting 5 10-19-2011 01:28 PM
To filter a log file dattatraya Shell Programming and Scripting 1 09-08-2008 10:51 PM
File filter Dastard Shell Programming and Scripting 3 09-06-2007 01:50 PM
filter out certain column from a file CamTu Shell Programming and Scripting 4 04-04-2005 06:24 PM



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