Re: replace the contents of file1 to file2.



explor wrote:
Hi,
I need replace the contents of file1 to file2. What's the best way to
achieve this? Basically i need to replace the entries in file2 by
file1 entries. file2 should have entries of file1.

To replace all entries in file1 by all entried in file2 is equivalent
to replace the file1 by file2; use the copy command: cp file2 file1

If, what seems more likely, you want to replace for each user name in
one file the corresponding entries with the same user name in the other
file then use

awk -F: 'NR==FNR{entry[$1]=$0;next}$1 in entry{$0=entry[$1]}1' f1 f2

where f1 f2 are either file1 file2 or file2 file1, depending where the
replacement shall take place (as I understand you, the former).

Janis

Please Help.

file1
root:x:4:0:Super:/:/sbin/sh
daemon:x:3:1::/:
bin:x:5:2::/usr/bin:
sys:x:7:3::/:
adm:x10:4:Adm:/var/adm

file2
root:x:0:0:Super-User:/:/sbin/sh
daemon:x:1:1::/:
bin:x:2:2::/usr/bin:
sys:x:3:3::/:
adm:x:4:4:Admin:/var/adm:
lp:x:71:8:Line Printer Admin:/usr/spool/lp:
uucp:x:5:5:uucp Admin:/usr/lib/uucp:
nuucp:x:9:9:uucp Admin:/var/spool/uucppublic:/usr/lib/uucp/uucico
smmsp:x:25:25:SendMail Message Submission Program:/:
listen:x:37:4:Network Admin:/usr/net/nls:
gdm:x:50:50:GDM Reserved UID:/:

.



Relevant Pages

  • Java algorithm (diff) question.
    ... I have two CSV files (file1 and file2). ... The entries in each file are not ... To generate the hashcode for each line and use the key and the ...
    (comp.lang.java.programmer)
  • Re: repalce the some lines of file1 to file2
    ... explor wrote: ... This is a requirment to keep the order ... The order they appear in file1 or in file2 or should new lines from file2 be added to the end of file1 or the beginning or mixed in alphabetically, ...
    (comp.lang.awk)
  • Re: joining files
    ... file1 has total 4 column but some of them are missing in few row. ... So What I want in the output is only those entries which is coming ...
    (comp.lang.python)
  • Re: Finding Unique entries between two large files
    ... the second has 320,000 entries in it. ... # Print record from file2 if you have not seen this record in file1 ...
    (comp.unix.shell)
  • Re: Java algorithm (diff) question.
    ... The first entry in each line is a key as shown in the example below. ... I would like to do a "diff"between file1 and file2 and ... The entries in each file are not ...
    (comp.lang.java.programmer)