Thank you but I'm not awk master at all,
visit comp.lang.awk and comp.unix.shell to see the real masters
Quote:
It's works, can you explain me how this exacly works, i want to understant
Sure, line by line.
While reading the first file - NR is the total number of input records seen so far, FNR - the input record number in the current input file, so the statement above is true only while we read the first file.
Store $1 and $3 as indexes in the array x. Populate the array y: the indexes are FNR,
the elements $2.
Skip the record(s) processed by these actions for the next statement(s)/action(s) (the code that follows will process
only the records that follow (the second file).
Now reading the second file. For the recors whose $1 and $3 are not in array x (in the first file) if the value of y[FNR]
(FNR now is the second file's record number) is not null, assign that value to $2.
I have some problem with replacing $2 from 2nd file; i think it is not cleaning if recor not found in file 2
all my deatils:
AWK FILE : match_files2_o.awk
BEGIN { printf "%-5s|%-10s|%-9s|%-9s|%-9s|%-70s|%-9s|%-s\n","Count", "VT", "Date", "Time","From","Alert Message","Instance",""}
NR == FNR {
x[$1,$7]
y[FNR] = $2
next
}
!(($1,$7) in x) {
if (y[FNR]) {
$2 = y[FNR]
}
{ printf "%-5s|%-10s|%-9s|%-9s|%-9s|%-70s|%-9s|%-s\n", $1, $2, $3, $4, $6, $7, $8, ""}
}
FILE 2: managed_event_log.170108
~~~~~~~~~
12~VT0000001~ 17-01-08~10:02:32~2~KAZUAT1~kaz/switch/bin/ifstart for KAZUAT1 TOO MANY PROCESSES 001459~emeflxci~FLEX_daemons~SWITCH:KAZ:T01~CRITICAL~~100
12~VT0000001~ 17-01-08~10:02:32~1~KAZUAT1~ifpoll_KZ for KAZUAT1 NOT EXIST 001459~emeflxci~FLEX_daemons~SWITCH:KAZ:T01~CRITICAL~~100
FILE 1: managed_event_log.170108
12~~ 17-01-08~10:02:32~1~KAZUAT1~ifpoll_KZ for KAZUAT1 NOT EXIST 001459~emeflxci~FLEX_daemons~SWITCH:KAZ:T01~CRITICAL~~100
12~~ 17-01-08~10:02:32~1~KAZUAT1~ifreader_KZ for KAZUAT1 NOT EXIST 001459~emeflxci~FLEX_daemons~SWITCH:KAZ:T01~CRITICAL~~100
12~~ 17-01-08~10:02:32~2~ISRUAT3~isr/switch/bin/ifstart for ISRUAT3 TOO MANY PROCESSES 102802~emeflxci~FLEX_daemons~SWITCH:ISR:T01~CRITICAL~~100
12~~ 17-01-08~10:02:32~2~KAZUAT1~kaz/switch/bin/ifstart for KAZUAT1 TOO MANY PROCESSES 001459~emeflxci~FLEX_daemons~SWITCH:KAZ:T01~CRITICAL~~100
1~~ 17-01-08~00:03:52~1~AUTOSYS~T01_ADM_155700_YYYYMMDD_C~T01~autosys~~JOBFAILURE~~
1~~ 17-01-08~00:03:10~1~AUTOSYS~T01_ADM_BO_yy-mm-dd_today_C~T01~autosys~~JOBFAILURE~~
1~~ 17-01-08~00:02:46~1~AUTOSYS~T01_ADM_BO_yy_mm_dd_today_C~T01~autosys~~JOBFAILURE~~
1~~ 17-01-08~00:03:11~1~AUTOSYS~T01_ADM_BO_yymmdd_today_C~T01~autosys~~JOBFAILURE~~
1~~ 17-01-08~00:03:08~1~AUTOSYS~T01_ADM_BO_yyyy-mm-dd_today_C~T01~autosys~~JOBFAILURE~~
1~~ 17-01-08~00:03:05~1~AUTOSYS~T01_ADM_BO_yyyy_mm_dd_today_C~T01~autosys~~JOBFAILURE~~
1~~ 17-01-08~00:03:04~1~AUTOSYS~T01_ADM_BO_yyyymmdd_today_C~T01~autosys~~JOBFAILURE~~
1~~ 17-01-08~00:05:39~1~AUTOSYS~T01_ADM_DateGvars_B~T01~autosys~~JOBFAILURE~~
1~~ 17-01-08~00:02:43~1~AUTOSYS~T01_ADM_GVAR_10235_DDMMYY_TODAY_C~T01~autosys~~JOBFAILURE~~
1~~ 17-01-08~00:04:17~1~AUTOSYS~T01_ADM_GVAR_149388_DATEDDMMMYYYY_C~T01~autosys~~JOBFAILURE~~
1~~ 17-01-08~00:04:23~1~AUTOSYS~T01_ADM_GVAR_149388_DATEMMMDD_C~T01~autosys~~JOBFAILURE~~
1~~ 17-01-08~00:03:11~1~AUTOSYS~T01_ADM_GVAR_35612_DATEyyyymmdd_LASTBUSDAY_C~T01~autosys~~JOBFAILURE~~
1~~ 17-01-08~00:04:57~1~AUTOSYS~T01_ADM_make_priv_C~T01~autosys~~JOBFAILURE~~
I execute it like this:
/usr/xpg4/bin/awk -f match_files2_o.awk FS="~" OFS="~" managed_event_log.output.170108 all_event_log.170108
I just tried following
ls *.dat|sort -t"_" -k2n,2|while read f1 && read f2; do
awk '{print}' $f1
awk FNR==1'{print $1,$2,$3,$4,$5,"*","*","*" }' OFS="\t" $f2
awk '{print}' $f2
donegot following result
18-Dec-1983 11:45:00 AM 18.692 84.672 0 25.4 24
18-Dec-1983 ... (3 Replies)
I have the urge to merge some files using unix shell script but I'm very new using this language and I haven't succeeded yet.
The requirement is to merge the header, body and footer into one file with the name "ANY-NAME" in below example. To identify which files should be merged, I have flagged... (9 Replies)
Hello,
I have a data format as follows:
Ind1 0 1 2
Ind1 0 2 1
Ind2 1 1 0
Ind2 2 2 0
I want to use AWK to have this output:
Ind1 00 12 21
Ind2 12 12 00
That is to merge each two rows with the same row names.
Thank you very much in advance for your help. (8 Replies)
Hi,
How I can merge two file columns such as the followings using awk:
file 1
2 3
2 2
1 1
file 2
4 3
4 5
7 6
Result:
2 3 4 3
2 2 4 5
1 1 7 6
This is an example, at the end, I will have about 25 files that I want to merge them, it is important for me that the order in the... (7 Replies)
Hello,
I am trying to merge data from two text files. One file (File1) contains a listing of data which includes the trial number in Column 5, while the other text file (File2) contains what category the trial belongs to.
Here is a snippet of what File1 looks like.
1 Arrow_ST 9.738 0.905... (2 Replies)
I want to write a scrpit to merge files row wise (actually concatinating)
main.txt
X Y Z
file 1
A B C
file 2
1 2 3
now i want the script to check if the file1 is empty or not, if empty then make it like
A B C
1 2 3
again to check if second file is empty if not do as done... (0 Replies)
1. if the 1st row IDs of input1 (ID1/ID2.....) is equal to any IDNames of input2
print all relevant values together as defined in the output.
2. A bit tricky part is IDno in the output. All we need to do is numbering same kind of
letters as 1 (aa of ID1) and different letters as 2 (ab... (4 Replies)
i have try , but i think i will never learn awk :(
now i have 2 files :
a
1:aaa:2:aaa1
2:bbb:2:bbb1
3:ccc:3:ccc1
b
aaa:2
bbb:0
ccc:3
output:
for all lines where a.$2 == b.$1
i want to compare a.$3 != b.$2 if true then set err=1 if false set err=0
and print all lines from file a +... (2 Replies)
Hi there,
I have a couple of files I need to merge. I can do a simple merge by concatenating them into one larger file.
But then I need to filter the file to get a desired result.
The output looks like this:
TRNH 0000000010941
ORDH
OADR
OADR
ORDL
ENDT 1116399 000000003... (2 Replies)