LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-02-2016, 10:03 AM   #1
torito
LQ Newbie
 
Registered: May 2016
Posts: 23

Rep: Reputation: Disabled
Smile which lines are identical in the two files


Hi everyone!

I am trying to write a command to find out which lines are identical in the two files.
I come up with grep -f file1 file2 > newfile

The problem is when I open newfile, it is empty. There is nothing there.

Any suggestions, please?

Thank you very much!
 
Old 06-02-2016, 10:26 AM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,812
Blog Entries: 1

Rep: Reputation: 259Reputation: 259Reputation: 259
Your command works for me. Maybe file1 and file2 have no lines in common.
 
Old 06-02-2016, 10:31 AM   #3
torito
LQ Newbie
 
Registered: May 2016
Posts: 23

Original Poster
Rep: Reputation: Disabled
Ummm.... interesting. I typed using vi an exact line in both files, but that line is not shown in the newfile.
 
Old 06-02-2016, 10:45 AM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Arch
Posts: 3,013

Rep: Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225
Does file1 have any special characters in it? (e.g. ".", "*", "\", "[", "]", etc)

You should use -F (fixed strings, rather then regexps)

Code:
grep -Ff file1 file2 > newfile
 
Old 06-02-2016, 10:52 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,245

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
You could also try looking at the comm command.
 
Old 06-02-2016, 11:08 AM   #6
torito
LQ Newbie
 
Registered: May 2016
Posts: 23

Original Poster
Rep: Reputation: Disabled
Thumbs up

Thank you everyone!!!!!!!!!!!!!!!!!!!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple (nearly) identical lines in dmesg when booting Slack64 14.1 paulb2 Slackware 3 11-09-2014 09:33 PM
[SOLVED] insert space between 2 identical lines papori Linux - Newbie 13 06-02-2014 03:45 AM
autofs local map files identical but not identical to automount jwaldram Linux - Server 2 10-26-2012 11:35 AM
[SOLVED] remove similar (not identical) lines of text steve51184 Linux - Software 5 04-25-2012 12:45 AM
remove identical lines in a file benjithegreat98 Linux - General 4 04-24-2004 07:12 AM


All times are GMT -5. The time now is 08:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration