• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to read one file and replace contents in another file

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have two files in unix. First file has only loan number and second file has lender number and loan number. I wanted to compare both loan numbers and update lender number with 909090. How do I do that.

Sample First File: First.txt
Loan Number
123456
333333
555555
888888
999999

Sample Second File: Second.txt
Lender Number,Loan Number
345900,123456
567209,888888
780909,345465

After executing the script output in Second.txt should be

Lender Number,Loan Number
909090,123456
909090,888888
780909,345465 ---> No change her, because loan number does not match from both the files.

Your help is grealy appreciated.



 
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The general approach is to write to a temporary file, and when you are done, delete the original file and rename the temporary file to the original file's name.
 
Ranch Hand
Posts: 136
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this:
Make sure your target file doesn't have space at the end of the line.

 
Sujoy Choudhury
Ranch Hand
Posts: 136
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did this help you?? Are you following your post??
 
reply
    Bookmark Topic Watch Topic
  • New Topic