Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I have two text files containing records in following format:file1 format is:
name1 age1 nickname1 path1
name2 age2 nickname2 path2file 1 example is:
abcd 13 abcd.13 /home/temp/abcd.13
efgh 15 efgh.15 /home/temp/new/efgh.15file 2 format is:
name1 age1 nickname1
name2 age2 nickname2file 2 example:
abcd 13 abcd.13
efgh 21 efgh.21file 2 is the current (up-to-date) file, and file 1 is the one that needs to update it's records to match file2. file1 contains records that might not exist in file2, and these records need to stay as-is. however, when updating, as in the above example, record efgh needs to be updated to reflect file2's values, so output should look like this:
output file:
abcd 13 abcd.13 /home/temp/abcd.13
efgh 21 efgh.21 /home/temp/new/efgh.21how can i achieve this with korn shell scripting (using awk maybe?)
thanks

awk 'FNR==NR{
a[$1] = $0;
next
}
(( $1 in a ) && ( a[$1] !~ $3)) {
split(a[$1],b," ")
gsub( $1".*$" ,b[3],$4)
printf "%s %s\n" ,a[$1] ,$4
next
}1
' file2 file1

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |