The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to delete content in a file (delete content only) kittusri9 Shell Programming and Scripting 5 05-15-2008 10:12 AM
file moving based on file content melvyn.cochrane Shell Programming and Scripting 12 02-15-2008 03:10 AM
extract content from a file and insert to another file fredao Shell Programming and Scripting 15 12-06-2006 04:36 PM
Using the content of a file in the name of another anriot Shell Programming and Scripting 2 09-18-2006 04:56 PM
transfer of specific file content to another file mem101 Shell Programming and Scripting 1 10-18-2005 11:01 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-18-2007
Registered User
 

Join Date: Sep 2007
Posts: 5
Content extract of a file using awk

Hi Everyone,

I have a file with the below content:

File1.txt
======
###
###==> the below table was created for testing1 purpose;
###
create table 123
(
field1 date,
field2 char(10)
primary key(field1)
);

###
###==> the below table was created for testing2 purpose;
###
create table abc
(
fielda1 date,
fielda2 char(10)
);


Question:
I would like to print only the 'create table' statements like below:

Sample Output:
===========
create table 123
(
field1 date,
field2 char(10)
primary key(field1)
);
create table abc
(
fielda1 date,
fielda2 char(10)
);


any hints would be much appreciated.


Thanks.

RaviShankar
Reply With Quote
Forum Sponsor
  #2  
Old 12-18-2007
Yogesh Sawant's Avatar
Part Time Moderator and Full Time Dad
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 798
Code:
egrep -v '^#|^$' file1.txt
Reply With Quote
  #3  
Old 12-18-2007
Registered User
 

Join Date: Sep 2007
Posts: 5
yeah i can use "grep -v" but i just want to know if this can be done thru' awk?
I want to learn more in awk.
Reply With Quote
  #4  
Old 12-19-2007
Yogesh Sawant's Avatar
Part Time Moderator and Full Time Dad
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 798
learning awk is very good, but also try to learn when to use what. if you can do something using grep, cut etc. why invoke awk and lose on performance? this would make it clear

this is one place for learning awk
Reply With Quote
  #5  
Old 12-19-2007
Klashxx's Avatar
HP-UX/Linux/Oracle
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 383
Hi , i agree with you.

Anyway the awk statement is :
Code:
awk ' $0 !~ /^#|^$/' file
Reply With Quote
  #6  
Old 12-19-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Code:
awk ' !/^#|^$/' file
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
awk, egrep

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:26 AM.


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

Content Relevant URLs by vBSEO 3.2.0