Необходимо найти разницу между двумя файлами SQL - file1.sql и file2.sql, используя AWK - PullRequest
0 голосов
/ 18 октября 2019

file1.sql

INSERT INTO `c' values
  (12,2101332,"test_run","2014-05-13 21:14:50",2,"ftrcjhnk","2014-05-13 21:14:50","2014-05-13 21:15:05"),
  (16,2101180,"test_run","2014-05-13 21:31:01",25,NULL,"2014-05-13 21:31:01","2014-05-13 21:31:01"),
  (17,2101216,"test_run","2014-05-13 21:36:00",30,NULL,"2014-05-13 21:36:00","2014-05-13 21:36:00"),
  (18,2086408,"test_run","2014-05-13 21:45:10",23,NULL,"2014-05-13 21:45:10","2014-05-13 21:45:10");

file2.sql

INSERT INTO `c' values
(12,2101332,"test_run","2014-05-13 21:14:50",2,"ftrcjhnk","2014-05-13 21:14:50","2014-05-13 21:15:05"),
(16,2101180,"test_run","2014-05-13 21:31:01",25,NULL,"2014-05-13 21:31:01","2014-05-13 21:31:01"),
(17,2101216,"test_run","2014-05-13 21:36:00",30,NULL,"2014-05-13 21:36:00","2014-05-13 21:36:00"),
(18,2086408,"test_run","2014-05-13 21:45:10",23,NULL,"2014-05-13 21:45:10","2014-05-13 21:45:10"),
(176,2115411,"test_run","2014-05-20 22:49:30",34,"JE-42162","2014-05-20 22:49:30","2014-05-20 22:49:50"),
(177,2106552,"test_run","2014-05-20 22:59:33",34,"JE-41185","2014-05-20 22:59:33","2014-05-20 22:59:38"),
(178,2107632,"test_run","2014-05-20 23:00:26",34,"JE-41185","2014-05-20 23:00:26","2014-05-20 23:00:32"),
(179,2118641,"test_run","2014-05-20 23:02:13",34,"JE-41185","2014-05-20 23:02:13","2014-05-20 23:02:18");

вывод должен быть

(176,2115411,"test_run","2014-05-20 22:49:30",34,"JE-42162","2014-05-20 22:49:30","2014-05-20 22:49:50"),
(177,2106552,"test_run","2014-05-20 22:59:33",34,"JE-41185","2014-05-20 22:59:33","2014-05-20 22:59:38"),
(178,2107632,"test_run","2014-05-20 23:00:26",34,"JE-41185","2014-05-20 23:00:26","2014-05-20 23:00:32"),
(179,2118641,"test_run","2014-05-20 23:02:13",34,"JE-41185","2014-05-20 23:02:13","2014-05-20 23:02:18");

Но, получая это, есть одна общая строкак обоим файлам, но отличаются только из-за ','

(18,2086408,"test_run","2014-05-13 21:45:10",23,NULL,"2014-05-13 21:45:10","2014-05-13 21:45:10"),
(176,2115411,"test_run","2014-05-20 22:49:30",34,"JE-42162","2014-05-20 22:49:30","2014-05-20 22:49:50"),
(177,2106552,"test_run","2014-05-20 22:59:33",34,"JE-41185","2014-05-20 22:59:33","2014-05-20 22:59:38"),
(178,2107632,"test_run","2014-05-20 23:00:26",34,"JE-41185","2014-05-20 23:00:26","2014-05-20 23:00:32"),
(179,2118641,"test_run","2014-05-20 23:02:13",34,"JE-41185","2014-05-20 23:02:13","2014-05-20 23:02:18"),

1 Ответ

0 голосов
/ 18 октября 2019

Не могли бы вы попробовать следующее.

awk '
FNR==NR{
  a[substr($0,1,length($0)-1)]
  next
}
!(substr($0,1,length($0)-1) in a)
'   Input_file1  Input_file2

Объяснение: Добавление пояснения к приведенному выше коду здесь.

awk '                                     ##starting awk program here.
FNR==NR{                                  ##Checking condition FNR==NR which will be TRUE when first Input_file is being read.
  a[substr($0,1,length($0)-1)]            ##Creating an array named a whose index is sub-string of current line from 1st letter to 2nd last letter(leaving last char).
  next                                    ##next will skip all further statements from here.
}                                         ##Closing BLOCK for FNR==NR condition here.
!(substr($0,1,length($0)-1) in a)         ##Checking condition if sub-string of current line from 1st char to till 2nd last char is NOT present in array a then print.
'  Input_file1  Input_file2               ##Mentioning Input_file names here.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...