search for columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting search for columns
# 1  
Old 09-16-2008
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
# 2  
Old 09-16-2008
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.
# 3  
Old 09-16-2008
Hi Era,
Its working ,Thanks for your reply .

Thanks,
Akil
# 4  
Old 09-16-2008
Hi Era,

I want to check for case senstive

example: create table...
Start_dt..
End_dt

Thanks,
Akil
# 5  
Old 09-17-2008
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.)
# 6  
Old 09-17-2008
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);

# 7  
Old 09-17-2008
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..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Search for columns with numbers greater than 70

This helped get me started. https://www.unix.com/unix-for-dummies-questions-and-answers/157026-need-command-search-numbers-greater-than-3000-a.html This is the command I am using. I am trying to find numbers greater than 70 in column 5. I do not know if it is getting confused because there... (6 Replies)
Discussion started by: cokedude
6 Replies

2. Shell Programming and Scripting

Always output 6 columns regardless of search results

If I am searching for AA then then BB in a loop, how do I make the output always contain 6 columns of comma separated data even when there may only be 4 search matches? AA11 AA12 AA13 AA14 BB11 BB12 BB13 BB14 BB15 BB16 Final output: AA11,AA12,AA13,AA14,,,... (14 Replies)
Discussion started by: jojojmac5
14 Replies

3. Shell Programming and Scripting

Need to search string from file 1 in one of columns of file 2

hello all. I would like to kindly ask you, if you could help me out with one problem. I have two files -> for ex. file1 and file2 file1 contains only various numbers file 2 contains multiple columns with various values What i need is to take every single number, one by one, from file 1 and... (3 Replies)
Discussion started by: wiety
3 Replies

4. Shell Programming and Scripting

Search based on 1,2,4,5 columns and remove duplicates in the same file.

Hi, I am unable to search the duplicates in a file based on the 1st,2nd,4th,5th columns in a file and also remove the duplicates in the same file. Source filename: Filename.csv "1","ccc","information","5000","temp","concept","new" "1","ddd","information","6000","temp","concept","new"... (2 Replies)
Discussion started by: onesuri
2 Replies

5. Shell Programming and Scripting

awk help to search columns in two files

Hello, I'm trying to compare multiple columns between two files. I would like to use columns 1,2 from file1 and search file2 in columns 2,3 for any matches. If they match, then print columns 2,3 from file2. file1 11:22:33:44:55:66|2010-07-25 12:30|xyz 22:22:22:22:22:22|2010-07-25... (5 Replies)
Discussion started by: pinseeker
5 Replies

6. Shell Programming and Scripting

Search multiple columns in each row

Hi All, I have to search in multiple columns for multiple values, if the match is found then print the values as below. Eg: cat t1 Z|VLD_AB_P|VLD_CD_P|VLD_EF_F|VLD_GH_F|100 Y|VLD_AB_F|VLD_CD_F|VLD_EF_P|VLD_GH_P|101 if then print "Invalid AB in $6" if then print "Invalid CD in... (6 Replies)
Discussion started by: gsjdrr
6 Replies

7. UNIX for Dummies Questions & Answers

Search for & edit rows & columns in data file and pipe

Dear unix gurus, I have a data file with header information about a subject and also 3 columns of n rows of data on various items he owns. The data file looks something like this: adam peter blah blah blah blah blah blah car 01 30 200 02 31 400 03 57 121 .. .. .. .. .. .. n y... (8 Replies)
Discussion started by: tintin72
8 Replies

8. Shell Programming and Scripting

awk/sed search lines in file1 matching columns in file2

Hi All, as you can see I'm pretty new to this board. :D I'm struggling around with small script to search a few fields in another file. Basically I have file1 looking like this: 15:38:28 sz:10001 pr:14.16 15:38:28 sz:10002 pr:18.41 15:38:29 sz:10003 pr:19.28 15:38:30 sz:10004... (1 Reply)
Discussion started by: floripoint
1 Replies

9. UNIX for Dummies Questions & Answers

Can I search columns and print lines?

Hi. First post here. I'm relatively new to UNIX (Solaris8) and writing my first real script, but I seem to have hit a brick wall. The odd thing is that it seems like it should be a simple task....but not with UNIX apparently. I've got a large text file: 14000 lines with 10 columns. I want... (2 Replies)
Discussion started by: Ant1815
2 Replies

10. Shell Programming and Scripting

Need help in AWK;Search String and rearrange columns

Hi AWK Experts, file1.txt contains: 29b11b820ddcc:-|OHad.perWrk|spn_id=AH111|spn_ordtyp=MY_REQ|msg_typ=ah.ntf.out|spn_ordid=928176|spn_nid=3|msg_strt=1175615334703|msg_que=oput|diff=371|17:48:55,074|17:48:55,084|10 file2.txt contains:... (2 Replies)
Discussion started by: spring_buck
2 Replies
Login or Register to Ask a Question