search for a string ,replace the whole line with new line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting search for a string ,replace the whole line with new line
# 1  
Old 08-06-2008
search for a string ,replace the whole line with new line

hai
i am very new to unix.

i am having two files like this.

first.properties

Code:
cache.ZA.TL_CCY=SELECT trim(CCY_CODE)||trim(COUNTRY_CODE)||trim(CITY_CODE) AS PK_COLUMN,CCY_CODE,COUNTRY_CODE,CITY_CODE,COUNTRY_CODE_TT,AVAILABLE_TT,AVAILABLE_BT,AVAILABLE_RTGS,AVAILABLE_ACH,AVAILABLE_PAY,AVAILABLE_LBC,AVAILABLE_IBC,AVAILABLE_OC,AVAILABLE_CC,DEC_PLACE,NEED_ROUNDING,ACTION_FLAG FROM TL_CCY
cache.ZA.TL_CLR_ZONE=SELECT trim(CLR_ZONE_CODE)||trim(COUNTRY_CODE)||trim(CITY_CODE) AS PK_COLUMN, CLR_ZONE_CODE,COUNTRY_CODE,CITY_CODE,CORR_BANK_CODE,IS_DUMMY,CCY_CODE FROM TL_CLR_ZONE
cache.ZA.TL_CUST=SELECT trim(CUST_ID)||trim(COUNTRY_CODE)||trim(CITY_CODE) AS PK_COLUMN,CUST_ID,COUNTRY_CODE,CITY_CODE,DELETED,FX_TOLERANCE_LIMIT FROM TL_CUST
cache.ZA.TL_CUST_DR_AC=SELECT trim(CUST_ID)||trim(COUNTRY_CODE)||trim(CITY_CODE)||trim(AC_NO) AS PK_COLUMN, CUST_ID,COUNTRY_CODE,CITY_CODE,AC_NO,CCY_CODE,DELETED,ASSIGN_CORP_CHQ_NO,PBOC_BANK_CODE,ALLOW_DUP_CORP_CHQ_NO FROM TL_CUST_DR_AC
cache.ZA.TL_DRAWEE_BANK=SELECT trim(CCY_CODE)||trim(BANK_CODE)||trim(COUNTRY_CODE)||trim(CITY_CODE) AS PK_COLUMN,  CCY_CODE,BANK_CODE,COUNTRY_CODE,CITY_CODE FROM TL_DRAWEE_BANK
cache.ZA.TL_DRAWEE_BANK_CHANNEL=SELECT trim(CCY_CODE)||trim(BANK_CODE)||trim(COUNTRY_CODE)||trim(CITY_CODE) AS PK_COLUMN, CCY_CODE,BANK_CODE,COUNTRY_CODE,CITY_CODE,DEFAULT_BANK FROM TL_DRAWEE_BANK_CHANNEL
cache.ZA.TL_FLAT_CHARGE=SELECT trim(PYMT_TYPE)||trim(PROC_MODE)||trim(COUNTRY_CODE)||trim(CITY_CODE) AS PK_COLUMN,PYMT_TYPE,PROC_MODE,COUNTRY_CODE,CITY_CODE,TIER_CHARGE,SERVICE_FEE FROM TL_FLAT_CHARGE
cache.ZA.TL_PICKUP_LOC=SELECT trim(PICKUP_LOC_CODE)||trim(COUNTRY_CODE)||trim(CITY_CODE) AS PK_COLUMN, PICKUP_LOC_CODE,COUNTRY_CODE,CITY_CODE FROM TL_PICKUP_LOC
cache.ZA.TL_PYMT_CENTRE= SELECT trim(COUNTRY_CODE)||trim(CITY_CODE) AS PK_COLUMN, COUNTRY_CODE,CITY_CODE,SELECT_WHT,SELECT_VAT,SELECT_DISCOUNT,SELECT_SERVICE,SELECT_BRANCH,SELECT_CLZ,CHK_INV_CHAR FROM TL_PYMT_CENTRE
cache.ZA.TL_SERVICE= SELECT trim(SERVICE_TYPE)||trim(COUNTRY_CODE)||trim(CITY_CODE) AS PK_COLUMN, SERVICE_TYPE,COUNTRY_CODE,CITY_CODE,PAYROLL_SERVICE FROM TL_SERVICE
cache.ZA.TL_SYS_PARM=SELECT trim(COUNTRY_CODE)||trim(CITY_CODE) AS PK_COLUMN, COUNTRY_CODE,CITY_CODE,PROC_BANK_CODE,BASE_CCY,LOCAL_CCY,SYS_CODE,TIME_ZONE_DIFF,FX_CNTL,FX_CNTL_LIMIT,FX_RATE_LIMIT,FAX_NO,MIDAS_BATCH_NO,TRAN_CODE,LOCAL_PYMT_CITY_CODE,DR_RES_MODE,CR_RES_MODE,FISC_NOSTRO_AC_NO,FISC_LIMIT,STRAIGHT_THROUGH_LIMIT,DR_MODE,CR_MODE,PRT_AFTER_DR,MAP_PYMT_TYPE,CHK_LOCAL_CCY_AMT,LLG_RTGS_LIMIT,LLG_CLR_ZONE_CODE FROM TL_SYS_PARM
cache.ZA.TL_CCY_CUTOFF_TIME=SELECT trim(PYMT_TYPE)||trim(PROC_MODE)||trim(CCY_CODE)||trim(COUNTRY_CODE)||trim(CITY_CODE) AS PK_COLUMN, PYMT_TYPE,PROC_MODE,CCY_CODE,COUNTRY_CODE,CITY_CODE,MON_CUTOFF_TIME,TUE_CUTOFF_TIME,WED_CUTOFF_TIME,THU_CUTOFF_TIME,FRI_CUTOFF_TIME,SAT_CUTOFF_TIME,SUN_CUTOFF_TIME FROM TL_CCY_CUTOFF_TIME




Change.txt

Code:
cache.ZA.TL_CLR_ZONE=SELECT trim(CCY_CODE) AS PK_COLUMN,CCY_CODE,NEED_ROUNDING FROM TL_CCY
 
cache.ZA.TL_SYS_PARM=SELECT trim(COUNTRY_CODE)||trim(CITY_CODE) AS PK_COLUMN,FISC_NOSTRO_AC_NO,FISC_LIMIT,STRAIGHT_THROUGH_LIMIT,DR_MODE,CR_MODE,PRT_AFTER_DR,MAP_PYMT_TYPE,CHK_LOCAL_CCY_AMT,LLG_RTGS_LIMIT,LLG_CLR_ZONE_CODE FROM TL_SYS_PARM





i want the output to be
First.properties

Code:
cache.ZA.TL_CCY=SELECT trim(CCY_CODE)||trim(COUNTRY_CODE)||trim(CITY_CODE) AS PK_COLUMN,CCY_CODE,COUNTRY_CODE,CITY_CODE,COUNTRY_CODE_TT,AVAILABLE_TT,AVAILABLE_BT,AVAILABLE_RTGS,AVAILABLE_ACH,AVAILABLE_PAY,AVAILABLE_LBC,AVAILABLE_IBC,AVAILABLE_OC,AVAILABLE_CC,DEC_PLACE,NEED_ROUNDING,ACTION_FLAG FROM TL_CCY

cache.ZA.TL_CLR_ZONE=SELECT trim(CCY_CODE) AS PK_COLUMN,CCY_CODE,NEED_ROUNDING FROM TL_CCY
 
cache.ZA.TL_CUST=SELECT trim(CUST_ID)||trim(COUNTRY_CODE)||trim(CITY_CODE) AS PK_COLUMN,CUST_ID,COUNTRY_CODE,CITY_CODE,DELETED,FX_TOLERANCE_LIMIT FROM TL_CUST
cache.ZA.TL_CUST_DR_AC=SELECT trim(CUST_ID)||trim(COUNTRY_CODE)||trim(CITY_CODE)||trim(AC_NO) AS PK_COLUMN, CUST_ID,COUNTRY_CODE,CITY_CODE,AC_NO,CCY_CODE,DELETED,ASSIGN_CORP_CHQ_NO,PBOC_BANK_CODE,ALLOW_DUP_CORP_CHQ_NO FROM TL_CUST_DR_AC
cache.ZA.TL_DRAWEE_BANK=SELECT trim(CCY_CODE)||trim(BANK_CODE)||trim(COUNTRY_CODE)||trim(CITY_CODE) AS PK_COLUMN,  CCY_CODE,BANK_CODE,COUNTRY_CODE,CITY_CODE FROM TL_DRAWEE_BANK
cache.ZA.TL_DRAWEE_BANK_CHANNEL=SELECT trim(CCY_CODE)||trim(BANK_CODE)||trim(COUNTRY_CODE)||trim(CITY_CODE) AS PK_COLUMN, CCY_CODE,BANK_CODE,COUNTRY_CODE,CITY_CODE,DEFAULT_BANK FROM TL_DRAWEE_BANK_CHANNEL
cache.ZA.TL_FLAT_CHARGE=SELECT trim(PYMT_TYPE)||trim(PROC_MODE)||trim(COUNTRY_CODE)||trim(CITY_CODE) AS PK_COLUMN,PYMT_TYPE,PROC_MODE,COUNTRY_CODE,CITY_CODE,TIER_CHARGE,SERVICE_FEE FROM TL_FLAT_CHARGE
cache.ZA.TL_PICKUP_LOC=SELECT trim(PICKUP_LOC_CODE)||trim(COUNTRY_CODE)||trim(CITY_CODE) AS PK_COLUMN, PICKUP_LOC_CODE,COUNTRY_CODE,CITY_CODE FROM TL_PICKUP_LOC
cache.ZA.TL_PYMT_CENTRE= SELECT trim(COUNTRY_CODE)||trim(CITY_CODE) AS PK_COLUMN, COUNTRY_CODE,CITY_CODE,SELECT_WHT,SELECT_VAT,SELECT_DISCOUNT,SELECT_SERVICE,SELECT_BRANCH,SELECT_CLZ,CHK_INV_CHAR FROM TL_PYMT_CENTRE
cache.ZA.TL_SERVICE= SELECT trim(SERVICE_TYPE)||trim(COUNTRY_CODE)||trim(CITY_CODE) AS PK_COLUMN, SERVICE_TYPE,COUNTRY_CODE,CITY_CODE,PAYROLL_SERVICE FROM TL_SERVICE

cache.ZA.TL_SYS_PARM=SELECT trim(COUNTRY_CODE)||trim(CITY_CODE) AS PK_COLUMN,FISC_NOSTRO_AC_NO,FISC_LIMIT,STRAIGHT_THROUGH_LIMIT,DR_MODE,CR_MODE,PRT_AFTER_DR,MAP_PYMT_TYPE,CHK_LOCAL_CCY_AMT,LLG_RTGS_LIMIT,LLG_CLR_ZONE_CODE FROM TL_SYS_PARM
cache.ZA.TL_CCY_CUTOFF_TIME=SELECT trim(PYMT_TYPE)||trim(PROC_MODE)||trim(CCY_CODE)||trim(COUNTRY_CODE)||trim(CITY_CODE) AS PK_COLUMN, PYMT_TYPE,PROC_MODE,CCY_CODE,COUNTRY_CODE,CITY_CODE,MON_CUTOFF_TIME,TUE_CUTOFF_TIME,WED_CUTOFF_TIME,THU_CUTOFF_TIME,FRI_CUTOFF_TIME,SAT_CUTOFF_TIME,SUN_CUTOFF_TIME FROM TL_CCY_CUTOFF_TIME


we have to search for the keys which found inside our change.txt in first.properties and replace the value of the key in first.properties with the corresponding value inside our change.txt


please help mein this scenario. it is an very urgent requirement.please help me .

thanks a lot in advance
Raja

Last edited by radoulov; 08-06-2008 at 07:24 AM.. Reason: please use code tags
# 2  
Old 08-06-2008
Try this:

Code:
awk 'NR==FNR{a[$1]=$0;next}a[$1]{print a[$1];next}{print}' "Change.txt" "first.properties"

Regards
# 3  
Old 08-07-2008
how can i make the changes in another file

Quote:
Originally Posted by Franklin52
Try this:

Code:
awk 'NR==FNR{a[$1]=$0;next}a[$1]{print a[$1];next}{print}' "Change.txt" "first.properties"

Regards

Hai Franklin,

Thanks a lot. i want to reflect the changes in some other file. please help me.

The code you gave diplays the changes what i need ,but want the first.properties should get updated every time when try this code.plz help me .
# 4  
Old 08-07-2008
Hi Franklin,
Thanks a lot, this code gives me the changes made in first.properties in display,but the file remains the same. i want to reflect the changes every time we do this command in first.properties permanently.plz help me

thanks in advance
# 5  
Old 08-07-2008
Redirect the output to a temporary file and replace the original file with it:

Code:
awk 'NR==FNR{a[$1]=$0;next}a[$1]{print a[$1];next}{print}' "Change.txt" "first.properties" > prop.tmp

mv prop.tmp first.properties

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Search for a string,delete the line and replace with new string in a file

Hi Everyone, I have a requirement in ksh where i have a set of files in a directory. I need to search each and every file if a particular string is present in the file, delete that line and replace that line with another string expression in the same file. I am very new to unix. Kindly help... (10 Replies)
Discussion started by: Pradhikshan
10 Replies

2. Shell Programming and Scripting

Multiple line search, replace second line, using awk or sed

All, I appreciate any help you can offer here as this is well beyond my grasp of awk/sed... I have an input file similar to: &LOG &LOG Part: "@DB/TC10000021855/--F" &LOG &LOG &LOG Part: "@DB/TC10000021852/--F" &LOG Cloning_Action: RETAIN &LOG Part: "@DB/TCCP000010713/--A" &LOG &LOG... (5 Replies)
Discussion started by: KarmaPoliceT2
5 Replies

3. Shell Programming and Scripting

String search and print next all lines in one line until blank line

Dear all I want to search special string in file and then print next all line in one line until blank lines come. Help me plz for same. My input file and desire op file is as under. i/p file: A1/EXT "BSCABD1_21233G1" 757 130823 1157 RADIO X-CEIVER ADMINISTRATION BTS EXTERNAL FAULT ... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

4. Shell Programming and Scripting

Search a string,get line and replace with second field

Hi, I need to search for source path in file2 , as per file1 and if found get the next line and take the field value and put it in URL value of file1. In file1, NF is not same for all the lines. file1: <type source="/home/USER/Desktop" Dest="/home/USER/DIR1/Desktop" URL="ssh/path"/> <type... (8 Replies)
Discussion started by: greet_sed
8 Replies

5. Shell Programming and Scripting

search a string in a particular column of file and return the line number of the line

Hi All, Can you please guide me to search a string in a particular column of file and return the line number of the line where it was found using awk. As an example : abc.txt 7000,john,2,1,0,1,6 7001,elen,2,2,0,1,7 7002,sami,2,3,0,1,6 7003,mike,1,4,0,2,1 8001,nike,1,5,0,1,8... (3 Replies)
Discussion started by: arunshankar.c
3 Replies

6. Solaris

Line too long error Replace string with new line line character

I get a file which has all its content in a single row. The file contains xml data containing 3000 records, but all in a single row, making it difficult for Unix to Process the file. I decided to insert a new line character at all occurrences of a particular string in this file (say replacing... (4 Replies)
Discussion started by: ducati
4 Replies

7. Shell Programming and Scripting

perl search and replace - search in first line and replance in 2nd line

Dear All, i want to search particular string and want to replance next line value. following is the test file. search string is tmp,??? ,10:1 "???" may contain any 3 character it should remain the same and next line replace with ,10:50 tmp,123 --- if match tmp,??? then... (3 Replies)
Discussion started by: arvindng
3 Replies

8. UNIX for Advanced & Expert Users

Search Parameter in first line and replace next line content

Hi, I need help. I have XML file as below &lt;a n=&quot;infoLevel&quot;&gt; &lt;v s=&quot;true&quot;/&gt; &lt;/a&gt; &lt;a n=&quot;localAddr&quot;&gt; &lt;v s=&quot;server.host.com&quot;/&gt; &lt;/a&gt; &lt;a n=&quot;ListenPort&quot;&gt; &lt;v s=&quot;21111&quot;/&gt; &lt;/a&gt; I need to find variable "ListenPort" in line and then replace... (4 Replies)
Discussion started by: rdtrivedi
4 Replies

9. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies

10. Shell Programming and Scripting

how to insert line break + string in vi (search & replace )

Hello all i have big test file that has allot of structure text something like this : <foo1 *.html> <blah action> somthing 1 somthing 2 </blah> </foo1 > now i will like to insert 2 more lines of text below the <blah action> so it will be like : <foo1... (1 Reply)
Discussion started by: umen
1 Replies
Login or Register to Ask a Question