Unix Shell - extract lines from file

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > May 2007 > extract lines from file





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author extract lines from file
surajkumar1@gmail.com

2007-05-22, 7:26 pm

Hi Friends,


I posted this questions few hours back and got some replies also but
it's not opening.


I want all those lines lines from file starting with keyword 'INSERT'
and end with ')'
Note: In following example there are two ')' (one after 'INSERT' and
another after 'VALUES') . I want all those lines between INSERT and
second occurence of ')'
############
Input File
########################################
###################################
INSERT common..dividend
( dividend_id,tid,declared_date,ex_date,re
cord_date,pay_date,amount,interim_final_
flag,

fx_rate,stock_option_ratio,stock_price,t
reaty_tax_rate,non_treaty_tax_rate,curre
ncy_code,

create_date,update_date,create_user_id,u
pdate_user_id,cam_id,orig_cam_id
)
VALUES (306181, 51758, '2007-05-11', '2007-05-21',
'2007-05-21', '2007-05-24', 0.19,
'I', 0.7426385949277784, null, 4.818, null,
null, 'EUR', '2007-05-11 03:04', '2007-05-11 03:04',
105,
105, 19874739, null
)

May 21, 2007 6:17:11 PM com.esdi.dividend.DividendAccrual
accrueDividends
INFO: START of accrual process for tid: 51745
May 21, 2007 6:17:11 PM com.esdi.dividend.DividendAccrual
accrueDividends
INFO: Instrument tid is 51745

INSERT common..dividend (

dividend_id,tid,declared_date,ex_date,re
cord_date,pay_date,amount,interim_final_
flag,

fx_rate,stock_option_ratio,stock_price,t
reaty_tax_rate,non_treaty_tax_rate,curre
ncy_code,

create_date,update_date,create_user_id,u
pdate_user_id,cam_id,orig_cam_id
)
VALUES (306177, 51745, '2007-05-11', '2007-05-21',
'2007-05-21', '2007-05-24', 0.015,
'I', 0.7426385949277784, null, 1.381, null,
null, 'EUR', '2007-05-11 03:04', '2007-05-11 03:04',
105,
105, 19874793, null
)

########################################
###################################

Output should be like following
======================
INSERT common..dividend
( dividend_id,tid,declared_date,ex_date,re
cord_date,pay_date,amount,interim_final_
flag,

fx_rate,stock_option_ratio,stock_price,t
reaty_tax_rate,non_treaty_tax_rate,curre
ncy_code,

create_date,update_date,create_user_id,u
pdate_user_id,cam_id,orig_cam_id
)
VALUES (306181, 51758, '2007-05-11', '2007-05-21',
'2007-05-21', '2007-05-24', 0.19,
'I', 0.7426385949277784, null, 4.818, null,
null, 'EUR', '2007-05-11 03:04', '2007-05-11 03:04',
105,
105, 19874739, null
)
INSERT common..dividend
( dividend_id,tid,declared_date,ex_date,re
cord_date,pay_date,amount,interim_final_
flag,

fx_rate,stock_option_ratio,stock_price,t
reaty_tax_rate,non_treaty_tax_rate,curre
ncy_code,

create_date,update_date,create_user_id,u
pdate_user_id,cam_id,orig_cam_id
)
VALUES (306181, 51758, '2007-05-11', '2007-05-21',
'2007-05-21', '2007-05-24', 0.19,
'I', 0.7426385949277784, null, 4.818, null,
null, 'EUR', '2007-05-11 03:04', '2007-05-11 03:04',
105,
105, 19874739, null
)


Thank you all in advance for your help.

Regards
SK

Michael Tosch

2007-05-23, 7:16 am

surajkumar1@gmail.com wrote:
> Hi Friends,
>
>
> I posted this questions few hours back and got some replies also but
> it's not opening.
>
>
> I want all those lines lines from file starting with keyword 'INSERT'
> and end with ')'
> Note: In following example there are two ')' (one after 'INSERT' and
> another after 'VALUES') . I want all those lines between INSERT and
> second occurence of ')'


Why not everything between INSERT and first following )
and everything between VALUES and first following )
?

The result should be the same.


--
Michael Tosch @ hp : com
Janis Papanagnou

2007-05-23, 1:18 pm

Michael Tosch wrote:
> surajkumar1@gmail.com wrote:
>
>
>
> Why not everything between INSERT and first following )
> and everything between VALUES and first following )
> ?


That's actually what my proposed solution was based upon;

awk '/INSERT/,/\)/;/VALUES/,/\)/'

that's two independent pattern ranges, each printing as default the
complete matching block.

>
> The result should be the same.
>
>


Janis
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com