The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 01:12 PM
file moving based on file content melvyn.cochrane Shell Programming and Scripting 12 02-15-2008 06:10 AM
extract content from a file and insert to another file fredao Shell Programming and Scripting 15 12-06-2006 07:36 PM
Using the content of a file in the name of another anriot Shell Programming and Scripting 2 09-18-2006 07:56 PM
transfer of specific file content to another file mem101 Shell Programming and Scripting 1 10-18-2005 02:01 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-19-2007
nr_shan nr_shan is offline
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
  #2 (permalink)  
Old 12-19-2007
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
Code:
egrep -v '^#|^$' file1.txt
  #3 (permalink)  
Old 12-19-2007
nr_shan nr_shan is offline
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.
  #4 (permalink)  
Old 12-19-2007
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
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
  #5 (permalink)  
Old 12-19-2007
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
  
 

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

Anyway the awk statement is :
Code:
awk ' $0 !~ /^#|^$/' file
  #6 (permalink)  
Old 12-19-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,507
Code:
awk ' !/^#|^$/' file
Sponsored Links
Closed Thread

Bookmarks

Tags
awk, egrep

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




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


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0