Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Linux command  'comm' and whitespace

Posted on 2014-11-20
2
Medium Priority
?
345 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

722 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