![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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.. |
|
|||||
|
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 |
|
||||
|
Quote:
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? |
|
|||||
|
well you could try something like:
Code:
sed 's/.* \(.*_t \).*/\1/g' infile Code:
tr " " "\n" <infile | grep _t$ |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|