Solved

Linux command  'comm' and whitespace

Posted on 2014-11-20
2
309 Views
Last Modified: 2014-11-22
I am seeing every single line show up on my comm comparison, because one file uses spaces, while the other uses tabs

Is there any way to get comm to print out the differences that exclude white space ?

Thanks
0
Comment
Question by:Anthony Lucia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 40455791
Alas, "comm" does not have such an option.

"diff" on the other hand, does have options for this, "-w" to ignore all whitespace and "-b" to ignore changes in the number of whitespaces.

diff -w a.conf b.conf

If you don't want to see the additional info which "diff" provides but only the changes:

diff -w a.conf b.conf | grep -E "^<|^>"

If you don't want to see the additional info which "diff" provides and finally filter out the "<" and ">" characters:

diff -w a.conf b.conf | grep "^<" | cut -f2- -d" "
(differences in file 1)

diff -w a.conf b.conf | grep "^>" | cut -f2- -d" "
(differences in file 2)

diff -w a.conf b.conf | grep -E "^<|^>" | cut -f2- -d" "
(all differences)
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 40455804
To work with "comm" nevertheless you could delete all whitespace before comparing:

sort b.conf | tr -d " \t" > b.conf.sorted
sort a.conf | tr -d " \t" | comm -2 -3 - b.conf.sorted
rm b.conf.sorted

Instead of " \t" you can use the "[:blank:]" character class.

The drawback with all of the above is that the final output will also lack the whitespaces.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question