dvah
March 23, 2011, 12:46pm
1
hi,
infile-
create table salary
( occupation_code char(40),
earnings decimal(10,2),
occ_yearend integer
);
outfile-
salary:create table salary
salary:( occupation_code char(40),
salary: earnings decimal(10,2),
salary: occ_yearend integer
salary:);
Thanks.
Try:
awk 'NR==1{x=$3}{$0=x":"$0}1' file
dvah
March 23, 2011, 1:03pm
3
The problem is my in file has many DDL scripts like below
create table contract_occ
( occupation_code char(40),
con_ref int,
cntrctid_number char(20));
create table salary
( occupation_code char(40),
earnings decimal(10,2),
occ_yearend integer);
...
contract_occ:create table contract_occ
contract_occ:( occupation_code char(40),
contract_occ: con_ref int,
contract_occ: cntrctid_number char(20));
salary:create table salary
salary:( occupation_code char(40),
salary: earnings decimal(10,2),
salary: occ_yearend integer);
...
So the append string varies acorss the script, the key here is to identify the table name with "create table" command and apply it to all the following lines till the next similar command exists.
Thanks.
awk '/create table/{x=$3}{$0=x":"$0}1' file
1 Like
dvah
March 23, 2011, 1:17pm
5
Thanks. This works perfect.
I just tried this with my own lengthy script, that works fine too.
while read line
do
if [ `echo $line | grep "create table " | wc -l` -gt 0 ]
then
tablename=`echo $line | awk '{print $3}'`
fi
echo "$tablename:" $line >> outfile
done < infile
Anyway, Thanks once again!