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
Search for a word on9west Shell Programming and Scripting 2 04-23-2008 04:15 AM
Word search in awk videsh77 Shell Programming and Scripting 8 03-08-2007 11:40 PM
search file for word, then assign to variable dejit UNIX for Dummies Questions & Answers 2 03-06-2007 01:57 PM
Search about word abu_hassan SUN Solaris 3 02-19-2007 01:17 PM
Can a shell script pull the first word (or nth word) off each line of a text file? tricky Shell Programming and Scripting 5 08-17-2006 07:29 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-08-2008
vishy vishy is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 4
search a word from file

Hello,
I have a file which contains some SQL statements. I need to take out the table name from the file. Table name will always end with "_t". can anyone help me in getting that?
for e.g.
---
SQL_STMT do_sql_insert: cmd="insert into account_t ( poid_DB, poid_ID0, poid_TYPE, poid_REV, business_type, account_type, name, account_no,
SQL_STMT dm_search_robj: cmd="select poid_DB, poid_ID0, poid_TYPE, poid_REV from bal_grp_t where bal_grp_t.account_obj_ID0 = :1
SQL_STMT do_sql_update: cmd="update account_t set poid_rev = poid_rev + 1, mod_t = :mod_t, currency=:currency, account_no=:account_no
---
Thanks in advance.

Last edited by vishy; 02-08-2008 at 12:39 PM..
  #2 (permalink)  
Old 02-08-2008
HPAVC's Avatar
HPAVC HPAVC is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 106
Something like ...
Code:
grep -v "_t" FILENAME
... obviously this will also match ...
Code:
UPDATE table set col="welcome to _town" ... ;
... you should / could use your favorite diff to inspect your changes ...
Code:
grep -v "_t" FILENAME >FILENAME2
diff FILENAME FILENAME2
  #3 (permalink)  
Old 02-08-2008
vishy vishy is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 4
this will give me the lines which does not contain "_t". what i want is the table name ....
so from my example i shld get...
account_t
bal_grp_t
account_t
  #4 (permalink)  
Old 02-08-2008
HPAVC's Avatar
HPAVC HPAVC is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 106
Code:
#!/usr/bin/perl
#
# cat SQLFILENAME | perl CODEFROMBELOWFILE.pl
#

use strict;

my %words;

while(my $line = <STDIN>)
{
   # munge line here to just deal with (select|delete) .* from (.*) (where|order by|group by|having) issues

    for my $word (split(/\s+/, $line))
    {
        $words{$word}++ if($word =~ m/^\w+_t$/i);
    }
}

for my $k (sort keys %words)
{
    print "$k\n";
}

Last edited by HPAVC; 02-08-2008 at 01:46 PM.. Reason: added usage
  #5 (permalink)  
Old 02-08-2008
vishy vishy is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 4
Quote:
Originally Posted by HPAVC View Post
Code:
#!/usr/bin/perl

use strict;

my %words;

while(my $line = <STDIN>)
{
    for my $word (split(/\s+/, $line))
    {
        $words{$word}++ if($word =~ m/^\w+_t$/i);
    }
}

for my $k (sort keys %words)
{
    print "$k\n";
}
Thanks for the solution...
but i m new to shell scripting... i m not able to understand this code.
can u pl. explain where i have to pass my file name and how to execute this code?
  #6 (permalink)  
Old 02-08-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431
save the code as a file e.g. perl-script

chmod the file to be exacutable.

then the following will work:

Code:
#  cat infile | ./perl-script
account_t
bal_grp_t
mod_t
FYI - this gives the same o/p as the sed cmd I suggested above...
  #7 (permalink)  
Old 02-08-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431
well you could try something like:

Code:
sed 's/.* \(.*_t \).*/\1/g' infile
or

Code:
tr " " "\n" <infile | grep _t$
but since you have things like mod_t in there, I'm guessing without a bit better parsing it won't be quite as exact as you'd like - may be good enough though depending on your overall sample size / whether this is a one-off etc
Closed Thread

Bookmarks

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 08:43 PM.


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