Re: replace the contents of file1 to file2.
- From: Janis Papanagnou <Janis_Papanagnou@xxxxxxxxxxx>
- Date: Wed, 16 May 2007 19:49:31 +0200
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:/:
- References:
- replace the contents of file1 to file2.
- From: explor
- replace the contents of file1 to file2.
- Prev by Date: repalce the some lines of file1 to file2
- Next by Date: tar statistics
- Previous by thread: replace the contents of file1 to file2.
- Next by thread: repalce the some lines of file1 to file2
- Index(es):
Relevant Pages
|