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!

SED script 1

Status
Not open for further replies.
Sep 22, 2004
27
0
0
US
Hi group,
i was trying to accomplish the following;

read file1 untill the line "B_comb" is encountered and not including the phrase "B_comb".(say line 181 has sql_seq_num B_comb; B_comb should be removed while reading all the lines upto "B_comb" and retainig 'sql_seq_num' but removing "B_comb").

remove any occurance of 'B.' only.

replace the occurance of
'(B.In_DT,'YYDD')' to '(OT_DT,'YYDDD')In_DT' .

read file2 and append to the end of file1,

copy the above appended to a new output file OUTDAT.

I tried with a crude script encopassing
sed '/s/B.//'file1 >file2.
But it replaced other occurance of B ( say Base_DT) to ' ase_DT)' which was not desired.
Please advice on the above.
Thanks a lot!
Roe
 
[tt]
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
[/tt]
 
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.
Thanks a lot again
Roe.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top