Solved

Linux command  'comm' and whitespace

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AWS EC2 Linux 1 55
Sendmail STARTTLS error 37 84
How can you tell your public IP address without a browser? 9 54
Choosing CentOS 16 62
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…
This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now