Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select a paragraph based on a word 2

Status
Not open for further replies.

vrrajeeb

Technical User
Feb 16, 2003
13
0
0
US
Hi,

1) I have a file (temp.lst) like this :

TABLE_A1
TABLE_C
TABLE_D

TABLE_B
TABLE_A
TABLE_E

TABLE_G
TABLE_F
TABLE_A2

I want to select the paragraph which has exactly TABLE_A in it ... (not TABLE_A1 or TABLE_A2)

The current solution I have is :

cat temp.lst|sed -e '/./{H;$!d;}' -e 'x;/TABLE_A/!d;'

But this prints out TABLE_A1 & TABLE_A2 as well ...

Is there a way to select the paragraph with exactly TABLE_A only ?

2) In the above question, I also need to dynamically select the table names from inside a loop ...

seq_tables_common.lst is a list of tables ... containing :

TABLE_A
TABLE_C
TABLE_D
TABLE_B
TABLE_E
TABLE_G
TABLE_F

cat seq_tables_common.lst|while read line
do
cat temp.lst|sed -e '/./{H;$!d;}' -e 'x;/$line/!d;' > $exp/tmp/$line.lst
done

But it doesn't select $line dynamically ... if I hard code the table names as TABLE_A, TABLE_A1 it works fine ... but substitution from within the single quotes is failing ...

Any ideas to fix these ?

Thanx in advance!

-Maria
 
Try this in the while loop...
[tt]
awk '$0 ~ v"[\t \n]"' RS= v=$line temp.lst
[/tt]
 
Ygor ...thanx for the response ...

1) It works fine if the table name is NOT the last line in a paragraph ... so it didn't select for TABLE_D, TABLE_E (also for TABLE_A1) ... for the rest, it selected fine ..

2) When the temp.lst is of the form :

IF V_SEQ_NAME = 'TABLE_A_1SQ' THEN
SELECT NVL(MAX(TABLE_A_ID), 0) INTO V_DUMMY_NO FROM TABLE_A;

IF V_SEQ_NAME = 'TABLE_A1_1SQ' THEN
SELECT NVL(MAX(TABLE_A1_ID), 0) INTO V_DUMMY_NO FROM TABLE_A1;

IF V_SEQ_NAME = 'TABLE_B_1SQ' THEN
SELECT NVL(MAX(TABLE_B_ID), 0) INTO V_DUMMY_NO FROM TABLE_B;

.............


Then I get the error :

awk: Line IF V_SEQ_NAME = 'TAB cannot have more than 199 fields.
The input line number is 139. The file is temp1.sql.
The source line number is 1.

Thanx again!

-Maria
 
Try this...
[tt]
awk '$0 ~ v"[^A-Za-z0-9_]"' RS= FS= v=$line temp.lst[/tt]
 
Works like a CHARM !!!

Thanx a great lot !

-Maria
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top