Solved

Linux command  'comm' and whitespace

Posted on 2014-11-20
2
240 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
  • 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Penetration Testing home based work 3 91
php56-php-mcrypt for rhel7 php56 1 51
Upgraded from Debian 7 to 8.7 and got black screen 20 67
The better OS Architecture 13 66
Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

861 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