0

I have two .csv files test_case_list.csv and test_case_summary.csv and I want to generate a third file that will have the difference of two files.

test_case_list.csv looks like:

cli-verify-cvlan-rewrite    ./vlan/vlan_rewrite_review.xls
cli-verify-cvlan-rewrite-lag    ./vlan/vlan_rewrite_review.xls
cli-verify-aggregation-general  ./link-aggr/aggregation.xls

test_case_summary.csv looks like:

*   cli-verify-aggregation-general  ./link-aggr/aggregation.xls
*   cli-verify-cvlan-rewrite    ./vlan/vlan_rewrite_review.xls

output: Another .xls or .csv file with

cli-verify-cvlan-rewrite-lag    ./vlan/vlan_rewrite_review.xls
1
  • diff a.csv b.csv > c.diff Nov 6, 2019 at 3:33

1 Answer 1

0

Using grep and sed:

grep -v -F -f <(sed 's/^[*[:space:]]*//' test_case_summary.csv) test_case_list.csv > diff.csv

The sed command removes all leading * and whitespace characters from test_case_summary.csv and this output is used as input for grep's -f option specifying a pattern file.

Option -F is used to interpret the patterns as fixed strings instead of regular expressions and -v selects non-matching lines, i.e. lines in test_case_list.csv which are not given in the pattern file. The output is then redirected to file diff.csv.

Additionally, you could add grep's -x option to only match whole lines.

2
  • This command is producing an empty file... Nov 6, 2019 at 5:17
  • Make sure test_case_summary.csv doesn't contain any blank/empty lines.
    – Freddy
    Nov 6, 2019 at 5:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .