Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

Vp1234▒▒▒▒
vp4567▒▒▒▒
vp6789-v2▒▒▒

(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
1  
Can you share how you failed to use sed for removing spaces? –  SparKot ॐ Feb 17 at 16:54
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.