Solved

Linux command  'comm' and whitespace

Posted on 2014-11-20
2
200 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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

772 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

10 Experts available now in Live!

Get 1:1 Help Now