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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SED script - modification

Status
Not open for further replies.
Sep 22, 2004
27
US
Futurlet,
Thanks alot for the superb script. Though the above awk does most of the tasks required, it however doesnt change the occurance of B. to " " as required. Also i need to
replace the occurance of
'(B.In_DT,'YYDD')' to '(OT_DT,'YYDDD')In_DT'.
Please advice on modifying the awk for the above changes. Also i would deeply appreciate if you could briefly explain the above awk. I tried referring to the syntax inorder to understand the awk statement that you had written,but it looks a bit complicated.
awk '
NR==FNR {
if (skipping)
next
if ( $0 ~ /B_comb/ )
{ sub( / *B_comb.*/, "" )
skipping = 1
}
else
if ( $0 ~ /^B\.$/ )
next
print
next
}
1
' file1 file2 >OUTDAT


Thanks a lot again
Roe.
 
[tt]
NR==FNR {
if (skipping)
next
sub( /\(B\.In_DT,'YYDD'\)/, "(OT_DT,'YYDDD')In_DT" )
sub( /B\./, "" )
if ( $0 ~ /B_comb/ )
{ sub( / *B_comb.*/, "" )
skipping = 1
}
print
next
}
1
[/tt]
 
futurlet,
The modified awk worked fine for the sub( /B\./, "" ),
but the
sub( /\(B\.In_DT,'YYDD'\)/, "(OT_DT,'YYDDD')In_DT" )
doesnt still substitute for the desired one.
I have oin the first line :
select to_char(A.BASE_DT, 'YYDDD') || 'M-G' || which needs to be changed to
select to_char(CYC_DT, 'YYDDD') BASE_DT.
i modified the awk to :
awk '
NR==FNR {
if (skipping)
next
sub ( /to_char \(A\.BASE_DT, 'YYDDD'\)/ , "to_char(CYC_DT, 'YYDDD') BASE_DT" )
sub ( /A\./ , "")
if ( $0 ~ /to_char \(A\.BASE_DT, 'YYDDD'\)/ )
{ sub ( /to_char \(A\.BASE_DT, 'YYDDD'\)/ , "to_char(CYC_DT, 'YYDDD') BASE_DT" )
skipping = 1
}

if ( $0 ~ /COMBINED_RECORD/ )
{ sub ( / *COMBINED_RECORD*/, "" )
skipping = 1
}
} 1
' file1 file2 > out.sql

sed 's/to_char \(BASE_DT, 'YYDDD'\)/to_char(CYC_DT, 'YYDDD') BASE_DT/' outdat.sql

But still it doesnt change to the desired output.
Please advice in the above.
Thanks a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top