![]() |
|
|
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 files with specfic extention and later search content | lovi_v | UNIX for Advanced & Expert Users | 2 | 07-14-2008 01:05 PM |
| Perl: Search for string on line then search and replace text | Crypto | Shell Programming and Scripting | 4 | 01-04-2008 10:24 AM |
| Can I search columns and print lines? | Ant1815 | UNIX for Dummies Questions & Answers | 2 | 04-26-2007 08:01 AM |
| Need help in AWK;Search String and rearrange columns | spring_buck | Shell Programming and Scripting | 2 | 04-05-2007 12:40 PM |
| Advanced Search Problems.. Search by User Name | Neo | Post Here to Contact Site Administrators and Moderators | 1 | 05-19-2003 01:28 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
search for columns
Hi I need to search for two columns START_DT,END_DT in file,if exists give tha table name.Please help Code:
ex: FILE.TXT CREATE TABLE AB (CD1 VARCHAR2(100), CD2 VARCHAR(50), START_DT DATE, END_DT DATE); CREATE TABLE AB1 (CD1 VARCHAR2(100), CD2 VARCHAR(50)); o/p should be Tablename :AB Thanks, Akil |
|
||||
|
Code:
awk '/CREATE TABLE /{table=$2; start=0; }
/START_DT/ { start++ }
/END_DT/ && start { print "Table name: " table }' file
... assuming END_DT always comes after START_DT, and CREATE TABLE marks the beginning of a new table. Basic Unix design philosophy dictates that a tool like this should simply just display the table names, without any user-friendly mark-up. |
|
||||
|
If your awk has the toupper function, you can use that to do case-insensitive comparisons. Code:
awk 'toupper($0) ~ /CREATE TABLE /{table=$2; start=0; }
toupper($0) ~ /START_DT/ { start++ }
toupper($0) ~ /END_DT/ && start { print table }' file
This creates an uppercase version of the input line, and compares that against the regular expressions. (I suppose it would be more economical to only invoke toupper once. If this is a time-critical operation, we can look at that.) |
|
||||
|
Code:
undef $/;
open FH,"<file.txt";
while(<FH>){
@arr=split("CREATE",$_);
for($i=0;$i<=$#arr;$i++){
$arr[$i]=~tr/\n/ /;
@temp=split(" ",$arr[$i]);
if($temp[6] eq "START_DT" && $temp[8] eq "END_DT"){
print "Tablename:",$temp[1],"\n";
}
}
}
close(FH);
|
|
||||
|
Hi Era, Thanks your great help .This waht I am looking ,Thanks a lot. Code:
Perl script which posted by summer_cherry its not working ,
temp[6] && $temp[8] {5th and 7th fields)
If Date columns may be different sequence
in some of the tables,In this case how can the below script can work?
ex:
Create table ..
cd1 char(10),
start_dt date,
desc varcha(200),
end_dt date));
##
undef $/;
open FH,"<file.txt";
while(<FH>){
@arr=split("CREATE",$_);
for($i=0;$i<=$#arr;$i++){
$arr[$i]=~tr/\n/ /;
@temp=split(" ",$arr[$i]);
if($temp[6] eq "START_DT" && $temp[8] eq "END_DT"){
print "Tablename:",$temp[1],"\n";
}
}
}
close(FH);
###
Thanks, Akil Last edited by akil; 09-17-2008 at 11:20 AM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|