Computing.Net > Forums > Unix > Replce string in file1 from file 2

Replce string in file1 from file 2

Reply to Message Icon

Original Message
Name: Mukesh
Date: May 12, 2005 at 22:15:56 Pacific
Subject: Replce string in file1 from file 2
OS: solaris 9
CPU/Ram: 256MHZ
Comment:

Hi ,

I have two files.
One has 100 rows like
XXX XR_DEF
YYY Y_DEF
...

Another file has 200 rows like
AR_DEF 1
Y_DEF 0
XR_DEF 100
...


I want to make another file like
XXX 100
YYY 0
...

If any pattern of 1st file is not found in 2nd then just ignore.
Please suggest me solution of this problem.


Thanks
Mukesh



Report Offensive Message For Removal


Response Number 1
Name: Luke Chi
Date: May 13, 2005 at 16:17:25 Pacific
Reply: (edit)

Porgram:

#!/usr/bin/sh

cp 100.txt tmp_1.txt

cat 200.txt | while read LINE
do
set $LINE
sed -e "s/ $1/ $2/" tmp_1.txt > tmp_2.txt
mv tmp_2.txt tmp_1.txt
done

cat tmp_1.txt

Output:

XXX 100
YYY 0


Luke Chi


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Replce string in file1 from file 2

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge