Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have to compare 2 files by using comm command like the below

comm -23 csv1 csv2 > csv3

I seem to face the problem that both the csv are generated from different sources (csv1 is extracted from another csv containing many columns and first column is extracted from it and csv 2 is generated from DB and consists of some extra spaces)

csv2 contains data like below


(where indicates a space). While csv1 contains similar data (which is why I have to compare to find the data only existing in csv1) but without spaces.

Hence its difficult to compare both.

I have tried sed but it didn't work or tried wrongly.

share|improve this question
Can you share how you failed to use sed for removing spaces? – SparKot Feb 17 '14 at 16:54

If the only issue are the spaces, you can try using diff instead of comm because it has the -w flag:

   -w, --ignore-all-space
          ignore all white space

You can then parse the output to mimic comm -23. For example:

diff -w  csv1 csv2 | grep -Po "^< \K.*" > csv3

Alternatively, you can remove all leading and trailing spaces from your file:

sed -i 's/ *$//; s/^ *//' csv2
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.