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}'

 
XZDIFF(1)							     XZ Utils								 XZDIFF(1)

NAME
xzcmp, xzdiff, lzcmp, lzdiff - compare compressed files SYNOPSIS
xzcmp [cmp_options] file1 [file2] xzdiff [diff_options] file1 [file2] lzcmp [cmp_options] file1 [file2] lzdiff [diff_options] file1 [file2] DESCRIPTION
xzcmp and xdiff invoke cmp(1) or diff(1) on files compressed with xz(1), lzma(1), gzip(1), or bzip2(1). All options specified are passed directly to cmp or diff. If only one file is specified, then the files compared are file1 (which must have a suffix of a supported com- pression format) and file1 from which the compression format suffix has been stripped. If two files are specified, then they are uncom- pressed if necessary and fed to cmp(1) or diff(1). The exit status from cmp or diff is preserved. The names lzcmp and lzdiff are provided for backward compatibility with LZMA Utils. SEE ALSO
cmp(1), diff(1), xz(1), gzip(1), bzip2(1), zdiff(1) BUGS
Messages from the cmp(1) or diff(1) programs refer to temporary filenames instead of those specified. Tukaani 2009-07-05 XZDIFF(1)
All times are GMT -4. The time now is 05:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy