Sponsored Content
Full Discussion: Add event
Top Forums UNIX for Dummies Questions & Answers Add event Post 302939957 by radius on Tuesday 31st of March 2015 07:05:47 AM
Old 03-31-2015
Add event

Hi all,

Need to solve this problem
file1.txt
Code:
0912804166|RR
0912804171|YY

file2.txt
Code:
0912804175|AXE|510100475741082
0912804166|NODE|0

I need to add event on file1.txt if column 1 in file1.txt is also found in file2.txt, the event is 1, but in contrary if column 1 in file1.txt is not found in file2.txt then the event added to the third column with 0

my expected output
Code:
0912804166|RR|1
0912804171|YY|0

I did this
Code:
awk -F'|' 'NR==FNR {h[$1] = $2; next} {FS=OFS="|";print $0,h[$1]}' file2.txt file1.txt | awk-F'|' '{if($3>0) print $0,"1"}{print $0,0}'

 
ZDIFF(1)						      General Commands Manual							  ZDIFF(1)

NAME
zcmp, zdiff - compare compressed files SYNOPSIS
zcmp [ cmp_options ] file1 [ file2 ] zdiff [ diff_options ] file1 [ file2 ] DESCRIPTION
Zcmp and zdiff are used to invoke the cmp or the diff program on files compressed via gzip. All options specified are passed directly to cmp or diff. If only file1 is specified, it is compared to the uncompressed contents of file1.gz. If two files are specified, their con- tents (uncompressed if necessary) are fed to cmp or diff. The input files are not modified. The exit status from cmp or diff is pre- served. SEE ALSO
cmp(1), diff(1), zmore(1), zgrep(1), znew(1), zforce(1), gzip(1), gzexe(1) BUGS
Messages from the cmp or diff programs may refer to file names such as "-" instead of to the file names specified. ZDIFF(1)
All times are GMT -4. The time now is 02:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy